-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (82 loc) · 2.88 KB
/
ci.yaml
File metadata and controls
97 lines (82 loc) · 2.88 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
name: CI
on:
pull_request:
branches: [main]
types: [closed]
push:
tags: ["v*"]
env:
DOCKER_IMAGE: moabdelazem/gitops-app
MANIFESTS_REPO: moabdelazem/gitops-sample-app-manifests
jobs:
build-and-push:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true || startsWith(github.ref, 'refs/tags/v')
outputs:
image_tag: ${{ steps.meta.outputs.IMAGE_TAG }}
is_release: ${{ steps.meta.outputs.IS_RELEASE }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set build metadata
id: meta
run: |
GIT_COMMIT=${GITHUB_SHA::7}
BUILD_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
IMAGE_TAG=$VERSION
IS_RELEASE=true
else
VERSION=$GIT_COMMIT
IMAGE_TAG=$GIT_COMMIT
IS_RELEASE=false
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "GIT_COMMIT=$GIT_COMMIT" >> $GITHUB_OUTPUT
echo "BUILD_TIME=$BUILD_TIME" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "IS_RELEASE=$IS_RELEASE" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
build-args: |
VERSION=${{ steps.meta.outputs.VERSION }}
GIT_COMMIT=${{ steps.meta.outputs.GIT_COMMIT }}
BUILD_TIME=${{ steps.meta.outputs.BUILD_TIME }}
tags: |
${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.IMAGE_TAG }}
${{ env.DOCKER_IMAGE }}:latest
update-manifests:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Checkout manifests repo
uses: actions/checkout@v4
with:
repository: ${{ env.MANIFESTS_REPO }}
token: ${{ secrets.MANIFESTS_PAT }}
- name: Update dev overlay
if: needs.build-and-push.outputs.is_release == 'false'
run: |
cd overlays/dev
sed -i "s|newTag:.*|newTag: ${{ needs.build-and-push.outputs.image_tag }}|" kustomization.yaml
- name: Update prod overlay
if: needs.build-and-push.outputs.is_release == 'true'
run: |
cd overlays/prod
sed -i "s|newTag:.*|newTag: ${{ needs.build-and-push.outputs.image_tag }}|" kustomization.yaml
- name: Commit and push
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add .
git commit -m "chore: update image to ${{ needs.build-and-push.outputs.image_tag }}"
git push