-
-
Notifications
You must be signed in to change notification settings - Fork 633
159 lines (141 loc) · 4.78 KB
/
docker-publish.yml
File metadata and controls
159 lines (141 loc) · 4.78 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
name: Publish Docker Images
on:
push:
branches:
- main
paths:
- "apps/server/**"
- "apps/dashboard/**"
- "apps/workflows/**"
- "apps/private-location/**"
- "apps/status-page/**"
- "apps/checker/**"
- "packages/**"
- "docker-compose.yaml"
workflow_dispatch:
inputs:
services:
description: 'Services to build (comma-separated)'
required: false
default: 'server,dashboard,workflows,private-location,status-page,checker'
type: string
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: openstatus
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
services: ${{ steps.set-services.outputs.services }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Determine services to build
id: set-services
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# Convert comma-separated input to JSON array
SERVICES=$(echo "${{ inputs.services }}" | tr ',' '\n' | jq -R . | jq -sc .)
else
# Detect changed files
CHANGED=$(git diff --name-only HEAD~1 HEAD)
SERVICES_LIST=()
# packages/** changes affect all services
if echo "$CHANGED" | grep -q '^packages/'; then
SERVICES_LIST=("server" "dashboard" "workflows" "private-location" "status-page" "checker")
else
for svc in server dashboard workflows private-location status-page checker; do
if echo "$CHANGED" | grep -q "^apps/$svc/"; then
SERVICES_LIST+=("$svc")
fi
done
fi
SERVICES=$(printf '%s\n' "${SERVICES_LIST[@]}" | jq -R . | jq -sc .)
fi
echo "services=$SERVICES" >> "$GITHUB_OUTPUT"
echo "Building services: $SERVICES"
build-and-push:
runs-on: ubuntu-latest
needs: [prepare]
if: needs.prepare.outputs.services != '[]'
timeout-minutes: 30
permissions:
contents: read
id-token: write
packages: write
strategy:
fail-fast: false
matrix:
service: ${{ fromJson(needs.prepare.outputs.services) }}
include:
- service: server
context: .
dockerfile: apps/server/Dockerfile
- service: dashboard
context: .
dockerfile: apps/dashboard/Dockerfile
- service: workflows
context: .
dockerfile: apps/workflows/Dockerfile
- service: private-location
context: apps/private-location
dockerfile: apps/private-location/Dockerfile
- service: status-page
context: .
dockerfile: apps/status-page/Dockerfile
- service: checker
context: apps/checker
dockerfile: apps/checker/Dockerfile
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Lowercase owner
run: echo "OWNER_LC=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.OWNER_LC }}/${{ env.IMAGE_NAME }}-${{ matrix.service }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix=
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
- name: Generate SBOM
uses: anchore/sbom-action@v0
with:
image: ${{ env.REGISTRY }}/${{ env.OWNER_LC }}/${{ env.IMAGE_NAME }}-${{ matrix.service }}@${{ steps.build.outputs.digest }}
format: spdx-json
output-file: sbom-${{ matrix.service }}.spdx.json
- name: Upload SBOM
uses: actions/upload-artifact@v4
with:
name: sbom-${{ matrix.service }}
path: sbom-${{ matrix.service }}.spdx.json
retention-days: 30