-
Notifications
You must be signed in to change notification settings - Fork 25
86 lines (75 loc) · 2.97 KB
/
docker-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
name: CI/CD Pipeline 24markets web
on:
push:
branches:
- develop
- main
jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
environment: ${{ github.ref == 'refs/heads/main' && 'production' || github.ref == 'refs/heads/develop' && 'development' }}
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Set Environment Variables Based on Branch
run: |
echo "DOCKER_IMAGE=${{ vars.ACR }}/web-${{ vars.ENV }}" >> $GITHUB_ENV
- name: Azure Container Registry login
uses: azure/docker-login@v2
with:
login-server: ${{ env.ACR }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Build and push Docker image
run: |
cp .env.${{ vars.ENVIRONMENT }} .env
docker build --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg RELEASE=$GITHUB_SHA \
--cache-from ${{ env.DOCKER_IMAGE }}:latest -f Dockerfile -t ${{ env.DOCKER_IMAGE }}:latest -t ${{ env.DOCKER_IMAGE }}:$GITHUB_SHA .
echo "${{ env.DOCKER_IMAGE }}:$GITHUB_SHA"
echo "Pushing image to ${{ env.DOCKER_IMAGE }}"
docker push ${{ env.DOCKER_IMAGE }}:latest
docker push ${{ env.DOCKER_IMAGE }}:$GITHUB_SHA
deploy:
permissions:
actions: read
contents: read
id-token: write
name: Deploy Helm Charts
needs: build
runs-on: ubuntu-latest
environment: ${{ github.ref == 'refs/heads/main' && 'production' || github.ref == 'refs/heads/develop' && 'development' }}
steps:
- name: Checkout code
uses: actions/[email protected]
# Logs in with your Azure credentials
- name: Azure Login
uses: Azure/[email protected]
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# Use kubelogin to configure your kubeconfig for Azure auth
- name: Set up kubelogin for non-interactive login
uses: azure/use-kubelogin@v1
with:
kubelogin-version: 'v0.0.25'
# Retrieves your Azure Kubernetes Service cluster's kubeconfig file
- name: Get K8s context
uses: azure/aks-set-context@v3
with:
resource-group: ${{ vars.RESOURCE_GROUP }}
cluster-name: ${{ vars.CLUSTER_NAME }}
admin: 'false'
use-kubelogin: 'true'
- name: Set Environment Variables Based on Branch
run: |
echo "DOCKER_IMAGE=${{ vars.ACR }}/web-${{ vars.ENV }}" >> $GITHUB_ENV
- name: Deploy Helm
run: |
helm upgrade --install web devops/helm \
--namespace ${{ vars.K8S_NAMESPACE }} \
--values devops/helm/env/${{ vars.VALUES_FILE }} \
--set image.repository=${{ env.DOCKER_IMAGE }} \
--set image.tag=$GITHUB_SHA \
--set imageCredentials.username=${{ secrets.ACR_USERNAME }} \
--set imageCredentials.password=${{ secrets.ACR_PASSWORD }} \
--atomic --timeout 5m0s