Skip to content

Commit

Permalink
build container images for workflows automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
skrobul committed Apr 3, 2024
1 parent 73dfb57 commit b163ae2
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 16 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/build-container-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
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/*'

# bump container versions here, they will be populated to tags and labels
env:
VERSION_PYTHON311: 0.0.1
VERSION_PYTHON312: 0.0.1
VERSION_PYTHON_IRONIC: 0.0.1

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
push: ${{ github.event_name != 'pull_request' }}
tags: ghcr.io/rackerlabs/understack/argo-python3.11.8-alpine3.19:latest,ghcr.io/rackerlabs/understack/argo-python3.11.8-alpine3.19:{{ env.VERSION_PYTHON311 }}
labels: |
org.opencontainers.image.version: "{{ env.VERSION_PYTHON311 }}"
- 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.python312_alpine
# push for all main branch commits
push: ${{ github.event_name != 'pull_request' }}
tags: ghcr.io/rackerlabs/understack/argo-python3.12.2-alpine3.19:latest,ghcr.io/rackerlabs/understack/argo-python3.12.2-alpine3.19:{{ env.VERSION_PYTHON312 }}
labels: |
org.opencontainers.image.version: "{{ env.VERSION_PYTHON312 }}"
- name: Build and deploy Python 3.11 with Ironic client
uses: docker/build-push-action@v5
with:
context: argo-workflows/ironic-nautobot-sync
file: argo-workflows/ironic-nautobot-sync/containers/Dockerfile.ironic
# push for all main branch commits
push: ${{ github.event_name != 'pull_request' }}
tags: ghcr.io/rackerlabs/understack/argo-ironic-client-python3.11.8:latest,ghcr.io/rackerlabs/understack/argo-ironic-client-python3.11.8:{{ env.VERSION_PYTHON_IRONIC }}
labels: |
org.opencontainers.image.version: "{{ env.VERSION_PYTHON_IRONIC }}"
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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.version="0.0.1"
LABEL org.opencontainers.image.base.name="ghcr.io/rackerlabs/understack/argo-python3.11.8-alpine3.19"
LABEL org.opencontainers.image.source=https://github.com/rackerlabs/understack

ENV PYTHONUNBUFFERED=1

Expand Down Expand Up @@ -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
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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.version="0.0.1"
LABEL org.opencontainers.image.base.name="ghcr.io/rackerlabs/understack/argo-python3.12.2-alpine3.19"
LABEL org.opencontainers.image.source=https://github.com/rackerlabs/understack

ENV PYTHONUNBUFFERED=1

Expand All @@ -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
Expand All @@ -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
#
Expand Down
2 changes: 0 additions & 2 deletions argo-workflows/ironic-nautobot-sync/container/build_images.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,8 +11,8 @@ 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.version="0.0.1"
LABEL org.opencontainers.image.base.name="ghcr.io/rackerlabs/understack/argo-ironic-client-python3.11.8"
LABEL org.opencontainers.image.source=https://github.com/rackerlabs/understack


ENV PATH="/opt/venv/bin:$PATH"
Expand All @@ -22,5 +22,5 @@ WORKDIR /app

USER $APP_USER

COPY --chown=${APP_USER}:${APP_GROUP} src/ /app
COPY --chown=${APP_USER}:${APP_GROUP} code/ /app
CMD ["python", "/app/main.py"]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b163ae2

Please sign in to comment.