Skip to content

Commit

Permalink
define all as env.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinSchiller committed Oct 17, 2023
1 parent 3497f9e commit f56a0fe
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
69 changes: 41 additions & 28 deletions .github/workflows/docker_debian_unified.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@ on:
env:
DOCKER_IMAGE_NAME: rpi-jukebox-rfid
CACHE_SCOPE: ${{ github.ref }}-debian-unified
LOCAL_REGISTRY_PORT: 5005
MATRIX_DEBIAN_VERSION_NAME: "['bullseye', 'buster']"
MATRIX_USERNAME: "['pi', 'hans']"
MATRIX_TEST_SCRIPT: "['run_installation_tests.sh', 'run_installation_tests2.sh', 'run_installation_tests3.sh']"

jobs:
prepare:
runs-on: ubuntu-latest

outputs:
runs_on: ubuntu-latest
platform: linux/arm/v7

# Definition of the matrix values for the subsequent jobs
matrix_debian_version: "['bullseye', 'buster']"
matrix_username: "['hans']" #"['pi', 'hans']"
matrix_test_script: "['run_installation_tests.sh', 'run_installation_tests2.sh', 'run_installation_tests3.sh']"
matrix_debian_version_name: ${{ env.MATRIX_DEBIAN_VERSION_NAME }}
matrix_username: ${{ env.MATRIX_USERNAME }}
matrix_test_script: ${{ env.MATRIX_TEST_SCRIPT }}

cache_scope: ${{ steps.set-cache_scope.outputs.cache_scope }}
image_tag_name: ${{ steps.set-image_tag_name.outputs.image_tag_name }}
image_tag_name_local_base: ${{ steps.set-image_tag_name_local_base.outputs.image_tag_name_local_base }}
image_file_path: ${{ steps.set-image_file_path.outputs.image_file_path }}
cache_scope: ${{ steps.set-cache_scope.outputs.cache_scope }}
cache_key: ${{ steps.set-cache_key.outputs.cache_key }}
local_registry_port: ${{ steps.set-local_registry_port.outputs.local_registry_port }}

steps:
- name: Set Output cache_scope
Expand All @@ -56,6 +62,13 @@ jobs:
id: set-cache_key
run: echo "cache_key=${{ steps.set-cache_scope.outputs.cache_scope }}-${{ github.sha }}#${{ github.run_attempt }}" >> $GITHUB_OUTPUT

- name: Set Output local_registry_port
id: set-local_registry_port
run: echo "local_registry_port=${{ env.LOCAL_REGISTRY_PORT }}" >> $GITHUB_OUTPUT

- name: Set Output image_tag_name_local_base
id: set-image_tag_name_local_base
run: echo "image_tag_name_local_base=localhost:${{ steps.set-local_registry_port.outputs.local_registry_port }}/${{ steps.set-image_tag_name.outputs.image_tag_name }}-base" >> $GITHUB_OUTPUT

build:
needs: [prepare]
Expand All @@ -64,12 +77,12 @@ jobs:
registry:
image: registry:2
ports:
- 5000:5000
- ${{ needs.prepare.outputs.local_registry_port }}:5000

strategy:
fail-fast: false
matrix:
debian_version: ${{ fromJSON(needs.prepare.outputs.matrix_debian_version) }}
debian_version_name: ${{ fromJSON(needs.prepare.outputs.matrix_debian_version_name) }}

steps:
- uses: actions/checkout@v4
Expand All @@ -91,12 +104,12 @@ jobs:
push: true
file: ./ci/Dockerfile.debian.test_install_unified.armv7
target: test
platforms: linux/arm/v7
tags: localhost:5000/${{ format( needs.prepare.outputs.image_tag_name, matrix.debian_version) }}-base
cache-from: type=gha,scope=${{ format( needs.prepare.outputs.cache_scope, matrix.debian_version) }}
cache-to: type=gha,mode=max,scope=${{ format( needs.prepare.outputs.cache_scope, matrix.debian_version) }}
platforms: ${{ needs.prepare.outputs.platform }}
tags: ${{ format( needs.prepare.outputs.image_tag_name_local_base, matrix.debian_version_name) }}
cache-from: type=gha,scope=${{ format( needs.prepare.outputs.cache_scope, matrix.debian_version_name) }}
cache-to: type=gha,mode=max,scope=${{ format( needs.prepare.outputs.cache_scope, matrix.debian_version_name) }}
build-args: |
DEBIAN_VERSION=${{ matrix.debian_version }}
DEBIAN_VERSION_NAME=${{ matrix.debian_version_name }}
GIT_BRANCH=${{ github.ref_name }}
GIT_URL=${{ github.server_url }}/${{ github.repository }}
Expand All @@ -109,29 +122,29 @@ jobs:
push: false
file: ./ci/Dockerfile.debian.test_install_unified.armv7
target: test-update
platforms: linux/arm/v7
tags: ${{ format( needs.prepare.outputs.image_tag_name, matrix.debian_version) }}
cache-from: type=gha,scope=${{ format( needs.prepare.outputs.cache_scope, matrix.debian_version) }}
# DON'T use 'cache-to' here as then the layer is cached and this build would be useless
outputs: type=docker,dest=${{ format( needs.prepare.outputs.image_file_path, matrix.debian_version) }}
platforms: ${{ needs.prepare.outputs.platform }}
tags: ${{ format( needs.prepare.outputs.image_tag_name, matrix.debian_version_name) }}
cache-from: type=gha,scope=${{ format( needs.prepare.outputs.cache_scope, matrix.debian_version_name) }}
# DON'T use 'cache-to' here as the layer is then cached and this build would be useless
outputs: type=docker,dest=${{ format( needs.prepare.outputs.image_file_path, matrix.debian_version_name) }}
build-args: |
BASE_TEST_IMAGE=localhost:5000/${{ format( needs.prepare.outputs.image_tag_name, matrix.debian_version) }}-base
BASE_TEST_IMAGE=${{ format( needs.prepare.outputs.image_tag_name_local_base, matrix.debian_version_name) }}
- name: Cache Check Docker Image
uses: actions/cache/restore@v3
id: cache-restore
with:
lookup-only: true
key: ${{ format( needs.prepare.outputs.cache_key, matrix.debian_version) }}
path: ${{ format( needs.prepare.outputs.image_file_path, matrix.debian_version) }}
key: ${{ format( needs.prepare.outputs.cache_key, matrix.debian_version_name) }}
path: ${{ format( needs.prepare.outputs.image_file_path, matrix.debian_version_name) }}

- name: Cache Save Docker Image
uses: actions/cache/save@v3
if: ${{ ! steps.cache-restore.outputs.cache-hit }}
with:
key: ${{ steps.cache-restore.outputs.cache-primary-key }}
path: ${{ format( needs.prepare.outputs.image_file_path, matrix.debian_version) }}
path: ${{ format( needs.prepare.outputs.image_file_path, matrix.debian_version_name) }}


test:
Expand All @@ -141,7 +154,7 @@ jobs:
strategy:
fail-fast: false
matrix:
debian_version: ${{ fromJSON(needs.prepare.outputs.matrix_debian_version) }}
debian_version_name: ${{ fromJSON(needs.prepare.outputs.matrix_debian_version_name) }}
username: ${{ fromJSON(needs.prepare.outputs.matrix_username) }}
test_script: ${{ fromJSON(needs.prepare.outputs.matrix_test_script) }}

Expand All @@ -155,19 +168,19 @@ jobs:
- name: Cache Restore Docker Image
uses: actions/cache/restore@v3
with:
key: ${{ format( needs.prepare.outputs.cache_key, matrix.debian_version) }}
path: ${{ format( needs.prepare.outputs.image_file_path, matrix.debian_version) }}
key: ${{ format( needs.prepare.outputs.cache_key, matrix.debian_version_name) }}
path: ${{ format( needs.prepare.outputs.image_file_path, matrix.debian_version_name) }}
fail-on-cache-miss: true

- name: Load Docker Image
run: |
docker load --input ${{ format( needs.prepare.outputs.image_file_path, matrix.debian_version) }}
docker load --input ${{ format( needs.prepare.outputs.image_file_path, matrix.debian_version_name) }}
- name: Run Test ${{ matrix.debian_version }}-${{ matrix.username }}-${{ matrix.test_script }}
- name: Run Test ${{ matrix.debian_version_name }}-${{ matrix.username }}-${{ matrix.test_script }}
uses: tj-actions/docker-run@v2
with:
image: ${{ format( needs.prepare.outputs.image_tag_name, matrix.debian_version) }}
options: --platform linux/arm/v7 --user ${{ matrix.username }}
image: ${{ format( needs.prepare.outputs.image_tag_name, matrix.debian_version_name) }}
options: --platform ${{ needs.prepare.outputs.platform }} --user ${{ matrix.username }}
name: ${{ matrix.test_script }}
args: |
./${{ matrix.test_script }}
10 changes: 5 additions & 5 deletions ci/Dockerfile.debian.test_install_unified.armv7
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Target to build and install all needed base configuration and packages
ARG DEBIAN_VERSION=bullseye
ARG DEBIAN_VERSION_NAME=bullseye
ARG BASE_TEST_IMAGE=test
FROM debian:${DEBIAN_VERSION}-slim as base
ARG DEBIAN_VERSION
FROM debian:${DEBIAN_VERSION_NAME}-slim as base
ARG DEBIAN_VERSION_NAME

ENV DOCKER_RUNNING=true
RUN touch /boot/cmdlinetxt
Expand All @@ -14,8 +14,8 @@ RUN apt-get update \
apt-utils \
curl \
gnupg \
&& echo "deb http://raspbian.raspberrypi.org/raspbian/ ${DEBIAN_VERSION} main contrib non-free rpi" > /etc/apt/sources.list.d/raspi.list \
&& echo "deb http://archive.raspberrypi.org/debian/ ${DEBIAN_VERSION} main" >> /etc/apt/sources.list.d/raspi.list \
&& echo "deb http://raspbian.raspberrypi.org/raspbian/ ${DEBIAN_VERSION_NAME} main contrib non-free rpi" > /etc/apt/sources.list.d/raspi.list \
&& echo "deb http://archive.raspberrypi.org/debian/ ${DEBIAN_VERSION_NAME} main" >> /etc/apt/sources.list.d/raspi.list \
&& curl http://raspbian.raspberrypi.org/raspbian.public.key | apt-key add - \
&& curl http://archive.raspberrypi.org/debian/raspberrypi.gpg.key | apt-key add - \
&& apt-get update \
Expand Down

0 comments on commit f56a0fe

Please sign in to comment.