-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (146 loc) · 5.35 KB
/
docker-publish.yml
File metadata and controls
164 lines (146 loc) · 5.35 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Publish daemons
# portions from gemini pro and fast
on:
schedule:
- cron: '30 3,12 * * *'
push:
branches: [ master ]
# Publish semver tags as releases.
tags: [ '*-v*.*.*' ]
paths: [ 'daemons/**' ]
pull_request:
branches: [ master ]
paths: [ 'daemons/**' ]
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Testing the container build mechanism'
env:
REGISTRY: ghcr.io
jobs:
setup-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
has_jobs: ${{ steps.set-matrix.outputs.has_jobs }}
steps:
- id: set-matrix
uses: actions/github-script@v8
env:
REF_NAME: ${{ github.ref_name }}
with:
script: |
const allContainers = [
'apphandler',
'authhandler',
'avsdispatcher',
'housekeeping',
'ltihandler',
'notepadhandler',
'noteshandler',
'staticserver'
]
const allContainersWithContext = allContainers.map((container) => ({
container,
context: './daemons/' + container
}))
const isTag = context.ref.startsWith('refs/tags/');
const refName = process.env.REF_NAME;
let activeContainers = allContainersWithContext;
if (isTag) {
activeContainers = allContainersWithContext.filter(c => refName.includes(c.container));
}
core.setOutput('has_jobs', activeContainers.length > 0);
core.setOutput('matrix', JSON.stringify({ include: activeContainers }));
build:
needs: setup-matrix
runs-on: ubuntu-latest
if: ${{ needs.setup-matrix.outputs.has_jobs == 'true' }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.setup-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Check for changes in ${{ matrix.context }}
id: changed
if: github.event_name == 'push' || github.event_name == 'pull_request'
uses: dorny/paths-filter@v4
with:
filters: |
src:
- '${{ matrix.context }}/**'
- name: Determine Build Status
id: check
run: |
# Default: Don't build
BUILD="false"
CLEAN_VER=""
if [[ "${{ github.event_name }}" == "schedule" || "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "Trigger: Schedule/Manual -> Building."
BUILD="true"
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "Trigger: Tag -> Building."
BUILD="true"
# Extract clean version (apphandler-v1.2.3 -> 1.2.3)
CLEAN_VER=$(echo "${{ github.ref_name }}" | sed 's/.*-v//')
elif [[ "${{ steps.changed.outputs.src }}" == "true" ]]; then
echo "Trigger: Push with changes -> Building."
BUILD="true"
else
echo "Trigger: Push but no changes -> Skipping."
fi
# Export to GITHUB_ENV so all next steps can see it simply
echo "SHOULD_BUILD=$BUILD" >> $GITHUB_ENV
echo "VERSION_TAG=$CLEAN_VER" >> $GITHUB_ENV
- name: Log into registry ${{ env.REGISTRY }}
if: env.SHOULD_BUILD == 'true' && github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
if: env.SHOULD_BUILD == 'true'
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.container }}
labels: |
org.opencontainers.image.title=${{ matrix.container }}
org.opencontainers.image.description=Component ${{ matrix.container }} from the fancy-lectures monorepo
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern=v{{version}},value=${{ env.VERSION_TAG }}
type=semver,pattern=v{{major}}.{{minor}},value=${{ env.VERSION_TAG }}
type=semver,pattern=v{{major}},value=${{ env.VERSION_TAG }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
if: env.SHOULD_BUILD == 'true'
uses: docker/build-push-action@v4
with:
context: .
file: ./${{ matrix.context }}/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
secrets: |
"GH_TOKEN=${{ secrets.GITHUB_TOKEN }}"