-
Notifications
You must be signed in to change notification settings - Fork 2
127 lines (115 loc) · 4.41 KB
/
build-and-publish.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
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
name: Docker
on:
schedule:
- cron: '18 2 * * *'
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: dbsystel/postgresql-partman
jobs:
build:
strategy:
matrix:
postgres_version: [13, 14, 15, 16, 17]
major: [4,5]
include:
- partman_version: v4.7.4
partman_checksum: 28e4fdb83ecc16525959ae9593bfbfd077db429285f5f7d8e2468bfff6cbdbf2c81ace79a9ddeb4f00f51eb709163dbd713fe6b221a432ac2ff766f98d4cf8e4
default: "true"
major: 4
- partman_version: v5.1.0
partman_checksum: 42f527f93c7c4da957a84d4b81dafc4b37beed8fe66d2b4d908386c8ed2256f7356a8af7bdc8b0f4281c65a6ceded8d114a0c7db715dd2cc093a6b15c5ae23f4
default: "false"
major: 5
exclude:
- major: 5
postgres_version: 13 # partman 5.x does not support postgres 13
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Install the cosign tool except on PR
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/[email protected]
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
# Login against a Docker registry except on PR
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ matrix.postgres_version == '15' && matrix.default == 'true' }}
type=raw,value=${{ matrix.postgres_version }},enable=${{ matrix.default == 'true'}}
${{ matrix.postgres_version }}-${{ matrix.major }}
# Build and push Docker image with Buildx, using only the digest
- name: Build and push Docker image with digest
id: build-and-push-digest
uses: docker/build-push-action@v5
with:
context: .
build-args: |
POSTGRESQL_VERSION=${{ matrix.postgres_version }}
PARTMAN_VERSION=${{ matrix.partman_version }}
PARTMAN_CHECKSUM=${{ matrix.partman_checksum }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pipeline
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Test the built Docker image using the digest
- name: Test Docker image
env:
POSTGRES_PASSWORD: examplepassword
run: |
DIGEST=${{ steps.build-and-push-digest.outputs.digest }}
docker run -d --name test-db -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@$DIGEST
sleep 30
docker exec test-db pg_isready -U postgres
docker stop test-db
docker rm test-db
# Build and push Docker image with Buildx,this time using the final tags
- name: Build and push Docker image with final tags (release)
id: build-and-push-release
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5
with:
context: .
build-args: |
POSTGRESQL_VERSION=${{ matrix.postgres_version }}
PARTMAN_VERSION=${{ matrix.partman_version }}
PARTMAN_CHECKSUM=${{ matrix.partman_checksum }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign the resulting Docker image digest except on PRs
- name: Sign the published Docker image
if: github.event_name != 'pull_request'
env:
COSIGN_EXPERIMENTAL: "true"
run: |
DIGEST=${{ steps.build-and-push-release.outputs.digest }}
TAGS=$(echo ${{ steps.meta.outputs.tags }} | tr ',' '\n')
for TAG in $TAGS; do
cosign sign -y $TAG
done