-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (132 loc) · 4.9 KB
/
cd.yml
File metadata and controls
153 lines (132 loc) · 4.9 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
name: CD
on:
push:
branches: [main]
tags: ["v*.*.*"]
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write # to update the release
packages: write # to pull and push images
env:
CARGO_TERM_COLOR: always
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
jobs:
guard:
name: Check if workflow should run
runs-on: ubuntu-slim
outputs:
should_run: ${{ steps.check.outputs.should_run }}
steps:
- name: Check commit message
id: check
run: |
if [[ "${{ github.ref_type }}" == "tag" ]]; then
echo "should_run=true" >> "$GITHUB_OUTPUT"
elif [[ "${{ github.event.head_commit.message }}" =~ ^repo:\ release\ .+ ]]; then
echo "should_run=false" >> "$GITHUB_OUTPUT"
else
echo "should_run=true" >> "$GITHUB_OUTPUT"
fi
build-binaries:
name: Build ${{ matrix.arch }} binaries
needs: [guard]
if: needs.guard.outputs.should_run == 'true'
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- arch: amd64
runner: ubuntu-24.04
target: x86_64-unknown-linux-gnu
- arch: arm64
runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
steps:
- name: Free up space
run: sudo rm -rf /opt/hostedtoolcache /usr/share/dotnet /usr/local/lib/android /opt/ghc /usr/local/.ghcup || true
- uses: actions/checkout@v6
with:
submodules: recursive
- name: Configure toolchain
run: |
rustup toolchain install --profile minimal --no-self-update stable
rustup default stable
rustup target add ${{ matrix.target }}
- uses: taiki-e/install-action@v2
with:
tool: just
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.arch }}-release
- name: Build binaries
run: cargo build --locked --target ${{ matrix.target }} --release --bin operator
env:
RUSTFLAGS: "-C target-feature=+crt-static"
- name: Prepare artifacts
run: |
mkdir -p artifacts/${{ matrix.arch }}
cp target/${{ matrix.target }}/release/operator artifacts/${{ matrix.arch }}/
- uses: actions/upload-artifact@v7
with:
name: binaries-${{ matrix.arch }}
path: artifacts/${{ matrix.arch }}/
retention-days: 1
build-images:
name: Build container images
runs-on: ubuntu-24.04
needs: [build-binaries]
steps:
- name: Login to ghcr.io
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- uses: actions/checkout@v6
with:
submodules: recursive
- name: Extract version
id: version
run: echo "version=$(cargo pkgid | cut -d# -f2)" >> "$GITHUB_OUTPUT"
- name: Download AMD64 binaries
uses: actions/download-artifact@v8
with:
name: binaries-amd64
path: .github/build-context/amd64/
- name: Download ARM64 binaries
uses: actions/download-artifact@v8
with:
name: binaries-arm64
path: .github/build-context/arm64/
- name: Debug build context structure
run: |
echo "=== Build context structure ==="
ls -laR .github/build-context/
echo "=== AMD64 binaries ==="
ls -lh .github/build-context/amd64/
echo "=== ARM64 binaries ==="
ls -lh .github/build-context/arm64/
- name: Setup buildkit
uses: docker/setup-buildx-action@v4
- uses: docker/metadata-action@v6
id: meta
with:
images: ghcr.io/beyondessential/postgres-restore-operator
tags: |
type=semver,value=v${{ steps.version.outputs.version }},pattern={{version}}
type=semver,value=v${{ steps.version.outputs.version }},pattern={{major}}.{{minor}}
type=semver,value=v${{ steps.version.outputs.version }},pattern={{major}}
labels: |
org.opencontainers.image.vendor=BES
org.opencontainers.image.title=Postgres Restore Operator
org.opencontainers.image.url=https://github.com/beyondessential/postgres-restore-operator/
org.opencontainers.image.source=https://github.com/beyondessential/postgres-restore-operator/
org.opencontainers.image.version=${{ steps.version.outputs.version }}
org.opencontainers.image.licenses=GPL-3.0-or-later
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .github/build-context
file: Containerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}