-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (117 loc) · 4.43 KB
/
build-deploy.yml
File metadata and controls
132 lines (117 loc) · 4.43 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
name: Build and Deploy CKAN
on:
push:
branches: [master, ckan211-prod-deploy-pr]
tags: ["v*"]
workflow_dispatch:
inputs:
image_tag:
description: "Image tag to deploy (e.g., sha-abc1234 or v1.0.0)"
required: true
type: string
environment:
description: "Target environment"
required: true
type: choice
options:
- staging
- production
env:
ACR_NAME: adracr
IMAGE_NAME: ckan
jobs:
build:
if: github.event_name != 'workflow_dispatch'
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.set-env.outputs.image_tag }}
environment: ${{ steps.set-env.outputs.environment }}
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
submodules: recursive
- name: Determine environment and image tag
id: set-env
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "environment=production" >> $GITHUB_OUTPUT
echo "image_tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
else
echo "environment=staging" >> $GITHUB_OUTPUT
echo "image_tag=sha-$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.6.1
with:
images: ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}
tags: |
type=sha
type=ref,event=tag
- name: Login to ACR
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: ${{ env.ACR_NAME }}.azurecr.io
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.10.0
with:
context: .
file: deploy/Dockerfile.prod
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy:
if: always() && (needs.build.result == 'success' || github.event_name == 'workflow_dispatch')
needs: build
runs-on: ubuntu-latest
environment:
name: ${{ github.event_name == 'workflow_dispatch' && inputs.environment || needs.build.outputs.environment }}
url: ${{ steps.params.outputs.url }}
steps:
- name: Set deploy params
id: params
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
ENV="${{ inputs.environment }}"
echo "image_tag=${{ inputs.image_tag }}" >> $GITHUB_OUTPUT
else
ENV="${{ needs.build.outputs.environment }}"
echo "image_tag=${{ needs.build.outputs.image_tag }}" >> $GITHUB_OUTPUT
fi
if [[ "$ENV" == "production" ]]; then
echo "namespace=adr-p" >> $GITHUB_OUTPUT
echo "url=https://adr-p.fjelltopp.org" >> $GITHUB_OUTPUT
else
echo "namespace=adr-s" >> $GITHUB_OUTPUT
echo "url=https://dev.adr.fjelltopp.org" >> $GITHUB_OUTPUT
fi
- name: Setup kubeconfig
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Deploy to AKS
run: |
# Determine env config file
if [[ "${{ steps.params.outputs.namespace }}" == "adr-p" ]]; then
ENV_CONFIG="deploy/production.ini"
else
ENV_CONFIG="deploy/staging.ini"
fi
# Create/update env ConfigMap
kubectl create configmap ckan-env-config \
--from-file=env.ini=$ENV_CONFIG \
-n ${{ steps.params.outputs.namespace }} \
--dry-run=client -o yaml | kubectl apply -f -
# Update image
kubectl set image deployment/ckan \
ckan=${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ steps.params.outputs.image_tag }} \
-n ${{ steps.params.outputs.namespace }}
kubectl rollout status deployment/ckan -n ${{ steps.params.outputs.namespace }} --timeout=5m