-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (119 loc) · 4.28 KB
/
rust.yaml
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
name: Rust
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
# Automatically cancel in-progress actions on the same branch
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
cancel-in-progress: true
env:
DOCKER_CONTAINER_IMAGE_BASE: lhr.ocir.io/lrdyqp2xtoja/cd-webhooks-forwarder
# get correct commit sha for pull requests as well
COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
target:
- rust: aarch64-unknown-linux-musl
docker: linux/arm64
# nix: aarch64-linux
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: "true"
- run: cargo install cross
- uses: docker/setup-buildx-action@v3
with:
install: true
- name: build
run: cross build --target ${{ matrix.target.rust }} --release
- name: Login to Docker registry
uses: docker/login-action@v2
with:
registry: lhr.ocir.io
username: ${{ secrets.OCIR_USERNAME }}
password: ${{ secrets.OCIR_TOKEN }}
- name: Docker meta tags generator
id: meta
uses: docker/metadata-action@v5
# use correct sha for pr commits
env:
DOCKER_METADATA_PR_HEAD_SHA: true
with:
images: |
${{ env.DOCKER_CONTAINER_IMAGE_BASE }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=edge
type=sha,format=long
- name: Build Dockerfile
id: build-and-push-action-1
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha
platforms: ${{ matrix.target.docker }}
build-args: |
RUST_TARGET_DIR=target/${{ matrix.target.rust }}/release
- run: docker push --all-tags $DOCKER_CONTAINER_IMAGE_BASE
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.DOCKER_CONTAINER_IMAGE_BASE }}:sha-${{ env.COMMIT_SHA }}
format: "table"
exit-code: "1"
ignore-unfixed: true
severity: "CRITICAL"
outputs:
pushed-image-digest: ${{ steps.build-and-push-action-1.outputs.digest }}
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.WRITE_BACK_TO_REPO_TOKEN }}
- name: install kustomize
id: kustomize-installation
run: |
curl -sfLo kustomize.tar.gz https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv4.5.7/kustomize_v4.5.7_linux_amd64.tar.gz
tar xzf ./kustomize.tar.gz
echo "KUSTOMIZE_COMMAND=$PWD/kustomize" >> $GITHUB_OUTPUT
- name: Update kustomization for new image
# in 'prod' folder
env:
KUSTOMIZE_COMMAND: ${{ steps.kustomize-installation.outputs.KUSTOMIZE_COMMAND }}
run: |
cd k8s/overlays/prod
# update image digest
$KUSTOMIZE_COMMAND edit set image \
${DOCKER_CONTAINER_IMAGE_BASE}=${DOCKER_CONTAINER_IMAGE_BASE}:sha-${COMMIT_SHA}@${{ needs.build.outputs.pushed-image-digest }}
- name: Update version label
uses: mikefarah/[email protected]
with:
cmd: yq -i '.labels[].pairs."app.kubernetes.io/version" = strenv(COMMIT_SHA)' k8s/overlays/prod/kustomization.yaml
- name: Commit to git
run: |
git config user.name github-actions
git config user.email [email protected]
git add k8s/overlays/prod
git commit -m "update: image to version $COMMIT_SHA
[no ci]"
git pull --rebase
git push
echo "Committed to infra" >> $GITHUB_STEP_SUMMARY