-
Notifications
You must be signed in to change notification settings - Fork 9
112 lines (104 loc) · 3.77 KB
/
build-and-push.yaml
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Build and Push
on:
workflow_call:
inputs:
changedPackages:
description: 'Changed Packages'
required: true
default: '[]'
type: string
secrets:
DOCKER_USERNAME:
description: 'Dockerhub Username'
required: true
DOCKER_PASSWORD:
description: 'Dockerhub Token'
required: true
jobs:
build-and-push:
runs-on: ubuntu-latest
if: ${{ inputs.changedPackages != '[]'}}
strategy:
fail-fast: false
matrix:
package: ${{fromJson(inputs.changedPackages)}}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v3
with:
version: 8
run_install: false
- run: echo "package=${{ matrix.package }}"
- name: get directory for package
id: get-directory
run: |
directory=$(pnpm ls -r --json --filter $MATRIX_PACKAGE --changed-files-ignore-pattern="**/(garden.yml|.dockerignore)" | jq -r '.[0] | .path')
directory="${directory##*/democracy-development/}"
# Ausgabe
echo "directory=$directory" >> $GITHUB_OUTPUT
env:
MATRIX_PACKAGE: ${{ matrix.package }}
- run: echo "directory=${{ steps.get-directory.outputs.directory }}"
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: democracy/${{ matrix.package }}
tags: |
type=ref,event=branch,enable=${{ github.ref == format('refs/heads/{0}', 'master') || github.ref == format('refs/heads/{0}', 'alpha') || github.ref == format('refs/heads/{0}', 'internal') }}
type=ref,event=pr
type=match,asref=foo,pattern=${{ matrix.package }}@v(\d+.\d+.\d+)(-alpha.\d+)?,group=1
type=semver,pattern={{version}},use=foo
type=sha,enable=${{ github.event_name == 'workflow_dispatch' }}
- name: Print Meta Summary
run: |
echo "🏷️ Tags: ${{ steps.meta.outputs.tags }}
" >> $GITHUB_STEP_SUMMARY
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-multi-buildx
- name: Login to DockerHub
if: ${{ github.actor != 'dependabot[bot]' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Read .node-version
id: node_version
run: echo "version=$(cat .node-version | tr -d 'v')" >> $GITHUB_OUTPUT
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
file: infra/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.actor != 'dependabot[bot]' }}
target: runner
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
build-args: |
SERVICE=${{ matrix.package }}
SERVICE_PATH=${{ steps.get-directory.outputs.directory }}
NODE_VERSION=${{ steps.node_version.outputs.version }}
- name: Move buildx cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}