From 7adbbd27c5a6de7ccbaf5b0ee52457fdb3d2b521 Mon Sep 17 00:00:00 2001 From: Marek Skrobacki Date: Tue, 2 Apr 2024 17:47:40 +0100 Subject: [PATCH] build container images for workflows automatically --- .github/workflows/build-container-images.yaml | 60 +++++++++++++++++++ .../{container => containers}/.gitkeep | 0 .../Dockerfile.python311_alpine | 6 +- .../Dockerfile.python312_alpine | 8 +-- .../container/build_images.sh | 2 - .../Dockerfile.ironic | 4 +- .../operate-workflow-sa-token.yaml | 0 .../synchronize-server-to-ironic.yaml | 2 +- 8 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/build-container-images.yaml rename argo-workflows/example-feature/{container => containers}/.gitkeep (100%) rename argo-workflows/generic/{ => containers}/Dockerfile.python311_alpine (81%) rename argo-workflows/generic/{ => containers}/Dockerfile.python312_alpine (76%) delete mode 100755 argo-workflows/ironic-nautobot-sync/container/build_images.sh rename argo-workflows/ironic-nautobot-sync/{container => containers}/Dockerfile.ironic (78%) rename argo-workflows/ironic-nautobot-sync/{container => deps}/operate-workflow-sa-token.yaml (100%) diff --git a/.github/workflows/build-container-images.yaml b/.github/workflows/build-container-images.yaml new file mode 100644 index 000000000..8291ca4d0 --- /dev/null +++ b/.github/workflows/build-container-images.yaml @@ -0,0 +1,60 @@ +--- +name: build-container-images + +on: + pull_request: + paths: + - 'argo-workflows/generic/containers/*' + - 'argo-workflows/ironic-nautobot-sync/containers/*' + push: + branches: + - main + paths: + - 'argo-workflows/generic/containers/*' + - 'argo-workflows/ironic-nautobot-sync/containers/*' + +jobs: + build-ghcr-registry: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to ghcr.io + if: ${{ github.event_name != 'pull_request' }} + uses: docker/login-action@v3 + with: + registry: "ghcr.io" + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and deploy Python 3.11 image + uses: docker/build-push-action@v5 + with: + context: argo-workflows/generic/ + file: argo-workflows/generic/containers/Dockerfile.python311_alpine + # push for all main branch commits and manually triggered runs + # push: ${{ github.event_name != 'pull_request' }} + tags: ghcr.io/rackerlabs/understack/argo-python3.11.8-alpine3.19:latest + + - name: Build and deploy Python 3.12 image + uses: docker/build-push-action@v5 + with: + context: argo-workflows/generic/ + file: argo-workflows/generic/containers/Dockerfile.python311_alpine + # push for all main branch commits and manually triggered runs + push: ${{ github.event_name != 'pull_request' }} + tags: ghcr.io/rackerlabs/understack/argo-python3.12.2-alpine3.19:latest + + - name: Build and deploy Python 3.11 with Ironic client + uses: docker/build-push-action@v5 + with: + context: argo-workflows/generic/ + file: argo-workflows/ironic-nautobot-sync/containers/Dockerfile.ironic + # push for all main branch commits and manually triggered runs + push: ${{ github.event_name != 'pull_request' }} + tags: ghcr.io/rackerlabs/understack/argo-ironic-client-python3.11.8 diff --git a/argo-workflows/example-feature/container/.gitkeep b/argo-workflows/example-feature/containers/.gitkeep similarity index 100% rename from argo-workflows/example-feature/container/.gitkeep rename to argo-workflows/example-feature/containers/.gitkeep diff --git a/argo-workflows/generic/Dockerfile.python311_alpine b/argo-workflows/generic/containers/Dockerfile.python311_alpine similarity index 81% rename from argo-workflows/generic/Dockerfile.python311_alpine rename to argo-workflows/generic/containers/Dockerfile.python311_alpine index 8b49a4166..18a3c8fc4 100644 --- a/argo-workflows/generic/Dockerfile.python311_alpine +++ b/argo-workflows/generic/containers/Dockerfile.python311_alpine @@ -1,7 +1,7 @@ -FROM trow.sno.rackspace.net/f/docker/python:3.11.8-alpine3.19 as builder +FROM python:3.11.8-alpine3.19 as builder LABEL org.opencontainers.image.title="Python 3.11 image base image" -LABEL org.opencontainers.image.base.name="registry.sno.rackspace.net/undercloud/argo-python3.11.8-alpine3.19" +LABEL org.opencontainers.image.base.name="ghcr.io/rackerlabs/understack/argo-python3.11.8-alpine3.19" LABEL org.opencontainers.image.version="0.0.1" ENV PYTHONUNBUFFERED=1 @@ -36,7 +36,7 @@ CMD ["python", "-"] # RUN --mount=type=cache,target=/var/cache/apk apk add --virtual build-deps gcc python3-dev musl-dev linux-headers # RUN --mount=type=cache,target=/root/.cache/.pip pip install --no-cache-dir python-ironicclient==5.4.0 # -# FROM trow.sno.rackspace.net/f/docker/python:3.11.8-alpine3.19 as prod +# FROM ghcr.io/rackerlabs/understack/argo-python3.11.8-alpine3.19 as prod # ENV PATH="/opt/venv/bin:$PATH" # COPY --from=builder /opt/venv /opt/venv # diff --git a/argo-workflows/generic/Dockerfile.python312_alpine b/argo-workflows/generic/containers/Dockerfile.python312_alpine similarity index 76% rename from argo-workflows/generic/Dockerfile.python312_alpine rename to argo-workflows/generic/containers/Dockerfile.python312_alpine index 38e62f28b..fd4e783b4 100644 --- a/argo-workflows/generic/Dockerfile.python312_alpine +++ b/argo-workflows/generic/containers/Dockerfile.python312_alpine @@ -1,7 +1,7 @@ -FROM trow.sno.rackspace.net/f/docker/python:3.12.2-alpine3.19 as builder +FROM python:3.12.2-alpine3.19 as builder LABEL org.opencontainers.image.title="Python 3.12 image base image" -LABEL org.opencontainers.image.base.name="registry.sno.rackspace.net/undercloud/argo-python3.12.2-alpine3.19" +LABEL org.opencontainers.image.base.name="ghcr.io/rackerlabs/understack/argo-python3.12.2-alpine3.19" LABEL org.opencontainers.image.version="0.0.1" ENV PYTHONUNBUFFERED=1 @@ -23,7 +23,7 @@ WORKDIR /app CMD ["python", "-"] # Example usage in final image -# FROM registry.sno.rackspace.net/undercloud/argo-python3.12.2-alpine3.19 +# FROM ghcr.io/rackerlabs/understack/argo-python3.12.2-alpine3.19 # # # This section needs to be repeated in child images # ARG APP_PATH=/app @@ -36,7 +36,7 @@ CMD ["python", "-"] # RUN --mount=type=cache,target=/var/cache/apk apk add --virtual build-deps gcc python3-dev musl-dev linux-headers # RUN --mount=type=cache,target=/root/.cache/.pip pip install --no-cache-dir python-ironicclient==5.4.0 # -# FROM trow.sno.rackspace.net/f/docker/python:3.12.2-alpine3.19 as prod +# FROM ghcr.io/rackerlabs/understack/argo-python3.12.2-alpine3.19 as prod # ENV PATH="/opt/venv/bin:$PATH" # COPY --from=builder /opt/venv /opt/venv # diff --git a/argo-workflows/ironic-nautobot-sync/container/build_images.sh b/argo-workflows/ironic-nautobot-sync/container/build_images.sh deleted file mode 100755 index 4bc3c6370..000000000 --- a/argo-workflows/ironic-nautobot-sync/container/build_images.sh +++ /dev/null @@ -1,2 +0,0 @@ -docker build -t registry.sno.rackspace.net/undercloud/argo-ironic:0.0.1 -f Dockerfile.ironic . -kind --name understack load docker-image registry.sno.rackspace.net/undercloud/argo-ironic:0.0.1 diff --git a/argo-workflows/ironic-nautobot-sync/container/Dockerfile.ironic b/argo-workflows/ironic-nautobot-sync/containers/Dockerfile.ironic similarity index 78% rename from argo-workflows/ironic-nautobot-sync/container/Dockerfile.ironic rename to argo-workflows/ironic-nautobot-sync/containers/Dockerfile.ironic index c34bc1169..852d43d7d 100644 --- a/argo-workflows/ironic-nautobot-sync/container/Dockerfile.ironic +++ b/argo-workflows/ironic-nautobot-sync/containers/Dockerfile.ironic @@ -1,4 +1,4 @@ -ARG BASE=registry.sno.rackspace.net/undercloud/argo-python3.11.8-alpine3.19:0.0.1 +ARG BASE=ghcr.io/rackerlabs/understack/argo-python3.11.8-alpine3.19:latest FROM ${BASE} as builder RUN --mount=type=cache,target=/var/cache/apk apk add --virtual build-deps gcc python3-dev musl-dev linux-headers @@ -11,7 +11,7 @@ ARG APP_GROUP=appgroup ARG APP_USER_UID=1000 ARG APP_GROUP_GID=1000 LABEL org.opencontainers.image.title="Python 3.11 image with Ironic Client" -LABEL org.opencontainers.image.base.name="registry.sno.rackspace.net/undercloud/argo-ironic" +LABEL org.opencontainers.image.base.name="ghcr.io/rackerlabs/understack/argo-ironic-client-python3.11.8" LABEL org.opencontainers.image.version="0.0.1" diff --git a/argo-workflows/ironic-nautobot-sync/container/operate-workflow-sa-token.yaml b/argo-workflows/ironic-nautobot-sync/deps/operate-workflow-sa-token.yaml similarity index 100% rename from argo-workflows/ironic-nautobot-sync/container/operate-workflow-sa-token.yaml rename to argo-workflows/ironic-nautobot-sync/deps/operate-workflow-sa-token.yaml diff --git a/argo-workflows/ironic-nautobot-sync/workflowtemplates/synchronize-server-to-ironic.yaml b/argo-workflows/ironic-nautobot-sync/workflowtemplates/synchronize-server-to-ironic.yaml index ba552dc33..6d0b25e50 100644 --- a/argo-workflows/ironic-nautobot-sync/workflowtemplates/synchronize-server-to-ironic.yaml +++ b/argo-workflows/ironic-nautobot-sync/workflowtemplates/synchronize-server-to-ironic.yaml @@ -10,7 +10,7 @@ spec: templates: - name: synchronize-server container: - image: registry.sno.rackspace.net/undercloud/argo-ironic:0.0.1 + image: ghcr.io/rackerlabs/understack/argo-ironic-client-python3.11.8:latest command: - python - /app/synchronize-server.py