Skip to content

Commit

Permalink
Generate modules Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
torchiaf committed Jan 3, 2025
1 parent 3721368 commit a485956
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 31 deletions.
4 changes: 0 additions & 4 deletions .github/actions/docker-push/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ runs:
with:
working-directory: ${{ inputs.working-directory }}

- name: Print
shell: bash
run: echo "${{ toJSON(inputs) }}"

- name: Build and push
uses: docker/build-push-action@v6
with:
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Generate Module Device list
shell: sh
run: echo "devices=$(sh ./scripts/list-directories.sh modules/${{ matrix.module }}/devices)"
- name: Generate Module Dockerfile
shell: sh
run: sh ./scripts/generate-module-dockerfile.sh ${{ matrix.module }} ${{ steps.run_tests.outputs.devices }} ${{ env.REGISTRY }} ${{ github.repository_owner }} ${{ env.REPO_LC }} ${{ github.ref_name }}
- name: Run Build and Publish Docker image
id: modules
uses: ./.github/actions/docker-push
Expand All @@ -90,8 +96,5 @@ jobs:
image-name: module/${{ matrix.module }}
tag-name: ${{ github.ref_name }}
working-directory: modules
file: modules/${{ matrix.module }}/Dockerfile
platforms: linux/arm64
# TODO 1 builder image arg for each device; needs to create a Dockerfile at runtime for each module, given the list of devices
build-args: |
LIB_IMAGE=${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.REPO_LC }}/device/dht11:${{ github.ref_name }}-${{ matrix.module }}
file: Dockerfile
platforms: linux/arm64
7 changes: 0 additions & 7 deletions modules/raspberrypi3b/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
ARG LIB_IMAGE=no-image

FROM ${LIB_IMAGE} AS lib

FROM python:3.9.21-alpine AS build

ADD ./rpc_server /rpc_server
Expand All @@ -24,6 +20,3 @@ FROM python:3.9.21-alpine
WORKDIR /rpc_server

COPY --from=build /dist/init /rpc_server
COPY --from=lib /dist/dht11 /rpc_server

CMD ["./init"]
7 changes: 0 additions & 7 deletions modules/raspberrypi5/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
ARG LIB_IMAGE=no-image

FROM ${LIB_IMAGE} AS lib

FROM debian AS build

ADD ./rpc_server /rpc_server
Expand All @@ -26,6 +22,3 @@ FROM ubuntu
WORKDIR /rpc_server

COPY --from=build /dist/init /rpc_server
COPY --from=lib /dist/dht11 /rpc_server

CMD ["./init"]
26 changes: 26 additions & 0 deletions scripts/generate-module-dockerfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

MODULE=$1
DEVICES=$(echo $2 | sed 's/,/ /g')

GITHUB_REGISTRY=$3
GITHUB_REPOSITORY_OWNER=$4
GITHUB_REPO=$5
GITHUB_REF_NAME=$6

echo "# Module: $MODULE, Devices: $2" > Dockerfile

for device in $DEVICES; do
echo "FROM $GITHUB_REGISTRY/$GITHUB_REPOSITORY_OWNER/$GITHUB_REPO/device/$device:$GITHUB_REF_NAME-$MODULE AS $device" >> Dockerfile
done
echo "" >> Dockerfile

echo "# Module: $MODULE build" >> Dockerfile
cat modules/$MODULE/Dockerfile >> Dockerfile

for device in $DEVICES; do
echo "COPY --from=$device /dist/$device /rpc_server" >> Dockerfile
done
echo "" >> Dockerfile

echo "CMD [\"./init\"]" >> Dockerfile
12 changes: 4 additions & 8 deletions scripts/list-directories.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/bin/sh

DIRECTORY=$1
OUTPUT=$2

ROOT=$1
RET=""

for dir in $(ls $DIRECTORY); do
RET=$(echo -n "$RET\"$dir\",")
for dir in $(ls $ROOT); do
RET=$(echo -n "$RET$dir,")
done

echo -n "$OUTPUT=["
echo -n $RET | sed 's/.$//'
echo "]"
echo $RET

0 comments on commit a485956

Please sign in to comment.