Skip to content

Commit

Permalink
Build docker config images (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngreatorex authored Oct 20, 2023
1 parent a7673ae commit 6a8724d
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 73 deletions.
1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

99 changes: 99 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Docker Image Builder

on:
workflow_call:
inputs:
platform:
description: 'The platform to build the image for'
required: true
type: string
path:
description: 'The path to the build context'
required: false
default: .
type: string
file:
description: 'The path to the Dockerfile'
required: false
default: ./Dockerfile
type: string
build-args:
description: 'Build args to be passed to Docker build'
required: false
default: ''
type: string
images:
description: 'The images to pass to the Docker metadata action'
required: true
type: string
tags:
description: 'The tags to pass to the Docker metadata action'
required: true
type: string
flavor:
description: 'The flavor to pass to the Docker metadata action'
required: false
default: ''
type: string
outputs:
tag:
description: 'The first tag generated by Docker for this build'
value: ${{ jobs.build-image.outputs.tag }}
secrets:
DOCKERHUB_TOKEN:
description: 'The token used to access Docker hub'
required: false

jobs:
build-image:
name: Build Docker image
runs-on: ubuntu-latest
env:
docker-token: ${{ secrets.DOCKERHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.images }}
tags: ${{ inputs.tags }}
flavor: ${{ inputs.flavor }}
- name: Get first tag
id: first-tag
run: |
echo -e ${{ toJson(steps.meta.outputs.tags) }} | { mapfile -t; echo "tag=${MAPFILE[0]}" >> $GITHUB_OUTPUT; echo "First tag: ${MAPFILE[0]}"; }
- name: Login to Docker Hub
uses: docker/login-action@v3
if: env.docker-token != ''
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR
uses: docker/login-action@v3
if: contains( inputs.images, 'ghcr.io' )
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[worker.oci]
max-parallelism = 2
- name: Build and push
uses: docker/build-push-action@v5
with:
build-args: ${{ inputs.build-args }}
file: ${{ inputs.file }}
context: ${{ inputs.path }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ inputs.platform }}
outputs:
tag: ${{ steps.first-tag.outputs.tag }}
57 changes: 0 additions & 57 deletions .github/workflows/docker-image.yml

This file was deleted.

77 changes: 77 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Docker CI

on:
push:
branches: [ "master" ]
tags: [ "v*.*.*" ]
pull_request:
branches: [ "master" ]
release:
types: [published]

jobs:

enumerate-configs:
name: Enumerate configs
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: set-matrix
name: Generate matrix with all configured Dockerfiles
run: |
echo "matrix=$(ls -l config/Dockerfile.* | grep '^-' | awk -F ' ' '{print $9}' | { read x; echo "${x##*.}"; } | jq -R -s -c 'split("\n") | map(select(length > 0))')" >> $GITHUB_OUTPUT
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

build-base-image:
name: Build base image
needs: enumerate-configs
uses: ./.github/workflows/build-docker-image.yml
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(vars.DOCKER_PLATFORMS) }}
with:
platform: ${{ matrix.platform }}
images: |
name=ngreatorex/homie-streamdeck,enable=${{ github.event_name != 'pull_request' }}
name=ghcr.io/${{ github.actor }}/homie-streamdeck,enable=${{ github.event_name == 'pull_request' }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
secrets: inherit

build-configured-images:
name: Build configured images
#if: github.event_name != 'pull_request'
needs:
- enumerate-configs
- build-base-image
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(vars.DOCKER_PLATFORMS) }}
config-name: ${{ fromJson(needs.enumerate-configs.outputs.matrix) }}
uses: ./.github/workflows/build-docker-image.yml
with:
build-args: |
FROM_IMAGE=${{ needs.build-base-image.outputs.tag }}
images: |
name=ghcr.io/${{ github.actor }}/homie-streamdeck-configured
flavor: |
suffix=_${{ matrix.config-name }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
platform: ${{ matrix.platform }}
path: config/
file: config/Dockerfile.${{ matrix.config-name }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
packages: write
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules/
config.json
/config.json
/*.png
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ COPY ["package.json", "package-lock.json*", "./"]

RUN npm install --omit=dev

COPY . .
COPY index.js /app/

CMD ["node", "index.js"]
5 changes: 0 additions & 5 deletions config/Dockerfile

This file was deleted.

13 changes: 13 additions & 0 deletions config/Dockerfile.raspi-a
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ARG FROM_IMAGE=ngreatorex/homie-streamdeck:master
FROM $FROM_IMAGE

COPY config.json /app/
COPY images /app/images/

WORKDIR /app
RUN ln -s images/Main_Off.png 0.png
RUN ln -s images/Uplight_Off.png 1.png
RUN ln -s images/Porch_Off.png 2.png
RUN ln -s images/Main_On.png 3.png
RUN ln -s images/Uplight_On.png 4.png
RUN ln -s images/Porch_On.png 5.png
18 changes: 18 additions & 0 deletions config/Dockerfile.raspi-streamdeck-one
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG FROM_IMAGE=ngreatorex/homie-streamdeck:master
FROM $FROM_IMAGE

COPY config.json /app/
COPY images /app/images/

WORKDIR /app
RUN ln -s images/Main_Off.png 0.png
RUN ln -s images/Uplight_Off.png 1.png
RUN ln -s images/Bedroom_Off.png 2.png
RUN ln -s images/Bedside_Off.png 3.png
RUN ln -s images/Porch_Off.png 4.png
RUN ln -s images/Main_On.png 5.png
RUN ln -s images/Uplight_On.png 6.png
RUN ln -s images/Bedroom_On.png 7.png
RUN ln -s images/Bedside_On.png 8.png
RUN ln -s images/Porch_On.png 9.png

3 changes: 3 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"mqtt_host": "mqtt.lan"
}
1 change: 0 additions & 1 deletion config/raspi-a/0.png

This file was deleted.

1 change: 0 additions & 1 deletion config/raspi-a/1.png

This file was deleted.

1 change: 0 additions & 1 deletion config/raspi-a/2.png

This file was deleted.

1 change: 0 additions & 1 deletion config/raspi-a/3.png

This file was deleted.

1 change: 0 additions & 1 deletion config/raspi-a/4.png

This file was deleted.

1 change: 0 additions & 1 deletion config/raspi-a/5.png

This file was deleted.

1 change: 0 additions & 1 deletion config/raspi-a/Dockerfile

This file was deleted.

0 comments on commit 6a8724d

Please sign in to comment.