forked from kamba4/sunders
Merge pull request 'Use kaniko to build image' (#39) from kaniko-build into main
Reviewed-on: #39
This commit is contained in:
commit
c90405d9ab
1 changed files with 63 additions and 48 deletions
|
|
@ -1,57 +1,72 @@
|
||||||
name: Build (and tag) Images
|
name: Build (and tag) Images
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_dispatch: {}
|
||||||
workflow_dispatch:
|
push: {}
|
||||||
|
|
||||||
|
# Every push builds both images. Only pushes to the main branch publish them, as
|
||||||
|
# `latest` and `sha-<commit>`; all other refs build without pushing and do not
|
||||||
|
# receive registry credentials.
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build-container:
|
||||||
runs-on: windows-2022
|
name: Build ${{ matrix.image }} Image
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: ghcr.io/osscontainertools/kaniko:alpine
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
image:
|
||||||
|
- web
|
||||||
|
- data_handler
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Install required system packages
|
||||||
|
run: apk add --no-cache nodejs git
|
||||||
|
|
||||||
|
- name: Checkout source code
|
||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Build image
|
||||||
uses: docker/setup-buildx-action@v4
|
env:
|
||||||
|
KANIKO_NO_PUSH: ${{ !(forgejo.event_name == 'push' && forgejo.ref == 'refs/heads/main') }}
|
||||||
|
KANIKO_GIT_HAMBURG_CCC_DE_USER: ${{ (forgejo.event_name == 'push' && forgejo.ref == 'refs/heads/main') && secrets.REGISTRY_USERNAME || '' }}
|
||||||
|
KANIKO_GIT_HAMBURG_CCC_DE_PASSWORD: ${{ (forgejo.event_name == 'push' && forgejo.ref == 'refs/heads/main') && secrets.REGISTRY_TOKEN || '' }}
|
||||||
|
run: /kaniko/executor
|
||||||
|
--dockerfile="${{ forgejo.workspace }}/${{ matrix.image }}/Containerfile"
|
||||||
|
--context="dir://${{ forgejo.workspace }}/${{ matrix.image }}"
|
||||||
|
--destination=git.hamburg.ccc.de/ccchh/sunders/${{ matrix.image }}:latest
|
||||||
|
--destination=git.hamburg.ccc.de/ccchh/sunders/${{ matrix.image }}:sha-${{ forgejo.sha }}
|
||||||
|
--no-push-cache
|
||||||
|
--credential-helpers=env
|
||||||
|
--annotation=org.opencontainers.image.ref.name=sunders/${{ matrix.image }}
|
||||||
|
--annotation=org.opencontainers.image.revision=${{ forgejo.sha }}
|
||||||
|
--annotation=org.opencontainers.image.url=${{ forgejo.server_url }}/${{ forgejo.repository }}
|
||||||
|
--annotation=org.opencontainers.image.source=${{ forgejo.server_url }}/${{ forgejo.repository }}
|
||||||
|
|
||||||
- name: Login to Container Registry
|
# Docker Compose smoke test, disabled: the current runner setup cannot execute it.
|
||||||
uses: docker/login-action@v4
|
# The `docker` runner runs jobs in a container without access to a Docker daemon
|
||||||
with:
|
# (which is why images are built with kaniko), so neither `docker build` nor
|
||||||
registry: git.hamburg.ccc.de
|
# `docker compose` is available. Re-enable this job once a runner with a Docker
|
||||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
# daemon exists, and set `runs-on` to its label.
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
#
|
||||||
|
# test-compose:
|
||||||
- name: Set image tags
|
# name: Test with Docker Compose
|
||||||
id: vars
|
# needs: build-container
|
||||||
run: |
|
# runs-on: docker # needs a runner with a Docker daemon
|
||||||
if [ "${{ github.ref_name }}" = "main" ] && [ "${{ github.event_name }}" = "push" ]; then
|
# steps:
|
||||||
echo "tag=latest" >> $GITHUB_OUTPUT
|
# - name: Checkout source code
|
||||||
else
|
# uses: actions/checkout@v7
|
||||||
# renovate creates sub branches with `/`; these break the tagging in the build process
|
#
|
||||||
echo tag=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9._-]/_/g') >> $GITHUB_OUTPUT
|
# - name: Build images
|
||||||
fi
|
# run: |
|
||||||
|
# docker build -f web/Containerfile -t git.hamburg.ccc.de/ccchh/sunders/web:ci web
|
||||||
- name: Build web image
|
# docker build -f data_handler/Containerfile -t git.hamburg.ccc.de/ccchh/sunders/data_handler:ci data_handler
|
||||||
run: |
|
#
|
||||||
docker buildx build -f ./Containerfile -t git.hamburg.ccc.de/ccchh/sunders/web:${{ steps.vars.outputs.tag }} --load .
|
# - name: Update docker-compose.yml image tags
|
||||||
working-directory: ./web
|
# run: |
|
||||||
|
# sed -i "s/:latest/:ci/g" docker-compose.yml
|
||||||
- name: Build data_handler image
|
#
|
||||||
run: |
|
# - name: Start Docker Compose services
|
||||||
docker buildx build -f ./Containerfile -t git.hamburg.ccc.de/ccchh/sunders/data_handler:${{ steps.vars.outputs.tag }} --load .
|
# run: |
|
||||||
working-directory: ./data_handler
|
# docker compose up -d --wait
|
||||||
|
# docker compose down
|
||||||
- name: Push images to Container Registry
|
|
||||||
run: |
|
|
||||||
docker push git.hamburg.ccc.de/ccchh/sunders/web:${{ steps.vars.outputs.tag }}
|
|
||||||
docker push git.hamburg.ccc.de/ccchh/sunders/data_handler:${{ steps.vars.outputs.tag }}
|
|
||||||
if: github.event_name == 'push'
|
|
||||||
|
|
||||||
- name: Update docker-compose.yml image tags
|
|
||||||
run: |
|
|
||||||
sed -i "s/:latest/:${{ steps.vars.outputs.tag }}/g" docker-compose.yml
|
|
||||||
|
|
||||||
- name: Start Docker Compose services
|
|
||||||
run: |
|
|
||||||
docker compose up -d --wait
|
|
||||||
docker compose down
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue