-
Notifications
You must be signed in to change notification settings - Fork 20
117 lines (105 loc) · 3.68 KB
/
Copy pathbuild-docker.yml
File metadata and controls
117 lines (105 loc) · 3.68 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
name: Build and Push Docker Images
permissions:
contents: write
packages: write
id-token: write
on:
workflow_run:
workflows: ["Release"]
types: [completed]
workflow_dispatch:
env:
REGISTRY: ghcr.io
ORGANIZATION: 256foundation
jobs:
build:
name: Build Docker Images
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
permissions:
contents: read
packages: write
id-token: write
strategy:
matrix:
component: [hydrapool, grafana, prometheus]
include:
- component: hydrapool
dockerfile: docker/Dockerfile.hydrapool
context: .
image_name: hydrapool
- component: grafana
dockerfile: docker/Dockerfile.grafana
context: .
image_name: hydrapool-grafana
- component: prometheus
dockerfile: docker/Dockerfile.prometheus
context: .
image_name: hydrapool-prometheus
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.workflow_run.head_sha || github.ref }}
fetch-depth: 0
- name: Get release tag
id: get_tag
run: |
if [ "${{ github.event_name }}" = "workflow_run" ]; then
TAG=$(git describe --tags --exact-match ${{ github.event.workflow_run.head_sha }} 2>/dev/null || echo "")
if [ -z "$TAG" ]; then
echo "No tag found for commit, using sha"
TAG="${{ github.event.workflow_run.head_sha }}"
fi
else
TAG="${{ github.ref_name }}"
fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "Found tag: $TAG"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/${{ matrix.image_name }}
tags: |
type=semver,pattern={{version}},value=${{ steps.get_tag.outputs.tag }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.get_tag.outputs.tag }}
type=raw,value=latest
type=sha
labels: |
org.opencontainers.image.description=Hydrapool ${{ matrix.component }} image
org.opencontainers.image.vendor=${{ env.ORGANIZATION }}
org.opencontainers.image.licenses=AGPL-3.0
org.opencontainers.image.visibility=public
- name: Build and push
id: build
uses: docker/build-push-action@v3
with:
context: ${{ matrix.context }}
file: ${{ matrix.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
- name: Sign the images
if: github.event_name != 'pull_request'
run: |
images="${{ steps.meta.outputs.tags }}"
for tag in ${images}; do
echo "Signing ${tag}@${{ steps.build.outputs.digest }}"
cosign sign --yes "${tag}@${{ steps.build.outputs.digest }}"
done
env:
COSIGN_EXPERIMENTAL: 1