-
Notifications
You must be signed in to change notification settings - Fork 1
106 lines (92 loc) · 3.49 KB
/
publish-image.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
name: Create and publish Realm Registry App image
on:
push:
branches:
- main
- dev
paths:
- 'app/**'
- 'helm/**'
- '.github/workflows/publish-image.yml'
env:
GITHUB_REGISTRY: ghcr.io
IMAGE_NAME: bcgov/sso-realm-registry
jobs:
build-and-push-image:
permissions: write-all
runs-on: ubuntu-20.04
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: hmarr/debug-action@v3
- uses: actions/checkout@v4
- name: Log in to the GitHub Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Create Release
if: github.ref == 'refs/heads/main'
id: release
uses: rymndhng/[email protected]
with:
bump_version_scheme: 'patch'
tag_prefix: 'v'
use_github_release_notes: 'true'
release_name: 'Release <RELEASE_VERSION>'
max_commits: 100 # default is 50
- id: get-tag
name: Get Tag
run: |
echo "release_tag=${{ endsWith(github.ref, '/main') && steps.release.outputs.tag_name || steps.meta.outputs.version }}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx-
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: app
push: true
tags: ${{ endsWith(github.ref, '/main') && format('{0}/{1}:{2}', env.GITHUB_REGISTRY, env.IMAGE_NAME, steps.release.outputs.tag_name) || steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Set env to development
if: (github.ref == 'refs/heads/dev' && github.event_name == 'push')
run: |
cat >> $GITHUB_ENV <<EOF
OPENSHIFT_TOKEN=${{ secrets.DEV_OPENSHIFT_TOKEN }}
OPENSHIFT_NAMESPACE=${{ secrets.DEV_OPENSHIFT_NAMESPACE }}
EOF
- name: Set env to production
if: (github.ref == 'refs/heads/main' && github.event_name == 'push')
run: |
cat >> $GITHUB_ENV <<EOF
OPENSHIFT_TOKEN=${{ secrets.PROD_OPENSHIFT_TOKEN }}
OPENSHIFT_NAMESPACE=${{ secrets.PROD_OPENSHIFT_NAMESPACE }}
EOF
- name: Authenticate and set context
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ env.OPENSHIFT_TOKEN }}
namespace: ${{ env.OPENSHIFT_NAMESPACE }}
insecure_skip_tls_verify: true
- name: Deploy app with Helm chart
run: |
namespace=${{ env.OPENSHIFT_NAMESPACE }}
helm dep up
helm upgrade --install --atomic realm-registry . -n ${namespace} \
-f values.yaml -f "values-${namespace}.yaml" --set image.tag="${{ steps.get-tag.outputs.release_tag }}"
working-directory: ./helm/webapp