Skip to content

Commit

Permalink
Generate Docker images on tag creation (Fixes #51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Oct 1, 2024
1 parent 2f13244 commit 2a83d2b
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 0 deletions.
163 changes: 163 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
name: 'kitconcept Intranet - Tag'

on:
push:
tags:
- '*'
workflow_dispatch:

env:
IMAGE_NAME_PREFIX: ghcr.io/kitconcept/kitconcept-intranet

jobs:

config:
runs-on: ubuntu-latest
outputs:
BASE_TAG: ${{ steps.vars.outputs.BASE_TAG }}
PLONE_VERSION: ${{ steps.vars.outputs.PLONE_VERSION }}
VOLTO_VERSION: ${{ steps.vars.outputs.VOLTO_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Compute several vars needed for the build
id: vars
run: |
echo 'BASE_TAG=sha-'$(git rev-parse --short HEAD) >> $GITHUB_OUTPUT
python3 -c 'from pathlib import Path; data = (Path() / "backend" / "version.txt").read_text().strip(); print(f"PLONE_VERSION={data}")' >> $GITHUB_OUTPUT
python3 -c 'import json; data = json.load(open("./frontend/mrs.developer.json")); print("VOLTO_VERSION=" + data["core"].get("tag") or "latest")' >> $GITHUB_OUTPUT
- name: Test vars
run: |
echo 'BASE_TAG=${{ steps.vars.outputs.BASE_TAG }}'
echo "PLONE_VERSION=${{ steps.vars.outputs.PLONE_VERSION }}"
echo 'VOLTO_VERSION=${{ steps.vars.outputs.VOLTO_VERSION }}'
backend:
runs-on: ubuntu-latest
needs:
- config
permissions:
contents: read
packages: write

steps:

- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME_PREFIX }}-backend
labels: |
org.label-schema.docker.cmd=docker run -d -p 8080:8080 ${{ env.IMAGE_NAME_PREFIX }}-backend:${{ github.ref_name }}
flavor:
latest=false
tags: |
type=ref,event=branch
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Backend image
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
context: backend
file: backend/Dockerfile
build-args: |
PLONE_VERSION=${{ needs.config.outputs.PLONE_VERSION }}
load: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Docker meta Beispiele
id: meta-beispiele
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME_PREFIX }}-beispiele
labels: |
org.label-schema.docker.cmd=docker run -d -p 8080:8080 ${{ env.IMAGE_NAME_PREFIX }}-beispiele:${{ github.ref_name }}
flavor:
latest=false
tags: |
type=ref,event=branch
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
context: backend
build-args: |
SEED=${{ github.run_id }}
IMAGE_TAG=${{ needs.config.outputs.BASE_TAG }}
file: backend/Dockerfile.beispiele
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-beispiele.outputs.tags }}
labels: ${{ steps.meta-beispiele.outputs.labels }}

frontend:
runs-on: ubuntu-latest
needs:
- config
permissions:
contents: read
packages: write

steps:

- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}
labels: |
org.label-schema.docker.cmd=docker run -d -p 3000:3000 ${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}:latest
flavor:
latest=false
tags: |
type=ref,event=branch
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
context: frontend/
file: frontend/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VOLTO_VERSION=${{ needs.config.outputs.VOLTO_VERSION }}
1 change: 1 addition & 0 deletions backend/news/51.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generate Docker images on tag creation [@ericof]
1 change: 1 addition & 0 deletions frontend/packages/volto-intranet/news/51.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generate Docker images on tag creation [@ericof]

0 comments on commit 2a83d2b

Please sign in to comment.