-
Notifications
You must be signed in to change notification settings - Fork 4
90 lines (80 loc) · 2.94 KB
/
build-docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Generic workflow to build a frontend application and push it to the GitHub Container Registry.
name: "Build docker"
on:
workflow_call:
inputs:
# Docker build arg / package name suffix: valid values are "admin-ui" or "ui"
app-name:
required: true
type: string
# Root url for the application relative to hostname
base-url:
required: true
type: string
env:
SKIP_ENV_VALIDATION: "true"
REGISTRY: "ghcr.io"
jobs:
build-and-push:
name: "Build and push Docker images to GitHub Packages"
runs-on: ubuntu-latest
env:
BUILD_APP: ${{ inputs.app-name }}
# Relative location for the package registry
REPO_NAME: ${{ github.repository }}
# Have to be build variable
NEXT_PUBLIC_BASE_URL: ${{ inputs.base-url }}
# required because error pages use build time env vars, not runtime env vars
# it's the same on every environment
EMAIL_VARAAMO_EXT_LINK: "https://lomake.hel.fi/varaamo-palaute"
permissions:
contents: read
packages: write
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v3
- name: "Log in to the Container registry"
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Repository name needs to be lowercase
- name: "Create repository name"
id: repo
run: >-
echo "repo=$(
echo ${{ env.REGISTRY }}/${{ env.REPO_NAME }}-${{ env.BUILD_APP }} | tr '[:upper:]' '[:lower:]'
)" >> $GITHUB_OUTPUT
- name: "Extract ui metadata (tags, labels) for Docker"
id: meta
uses: docker/metadata-action@v5
env:
DOCKER_METADATA_PR_HEAD_SHA: true
with:
images: ${{ steps.repo.outputs.repo }}
tags: |
type=ref,event=tag,priority=3
type=sha,prefix=,priority=2
type=ref,event=branch,priority=1
labels: |
org.opencontainers.image.title=Tilavarauspalvelu ${{ env.BUILD_APP }}
org.opencontainers.image.description=Tilavarauspalvelu ${{ env.BUILD_APP }} ${{ github.ref_name }}.
org.opencontainers.image.version=${{ github.ref_name }}
- name: "Build container"
uses: docker/build-push-action@v6
with:
context: .
push: true
build-args: |
APP=${{ env.BUILD_APP }}
NEXT_PUBLIC_BASE_URL=${{ env.NEXT_PUBLIC_BASE_URL }}
EMAIL_VARAAMO_EXT_LINK=${{ env.EMAIL_VARAAMO_EXT_LINK }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
# Use a shared cache to speed up builds
cache-from: type=registry,ref=${{ steps.repo.outputs.repo }}:cache
cache-to: type=registry,ref=${{ steps.repo.outputs.repo }}:cache,mode=max