This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
65 lines (61 loc) · 2.53 KB
/
publish.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
name: Deploy
on: [push]
jobs:
publish_image:
runs-on: ubuntu-latest
outputs:
app_version: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set application version
id: app_version
run: echo "::set-output name=prefix::$(date +'%Y-%m-%d').${{ github.run_number }}."
- name: Generate docker image tags and labels
id: meta
uses: docker/metadata-action@v3
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=sha,priority=2000,format=short,prefix=${{ steps.app_version.outputs.prefix }},enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=ref,event=branch
- name: Login to container registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push docker image
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
needs: [publish_image]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Authenticate to the cluster
env:
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
KUBE_CERT: ${{ secrets.KUBE_CERT }}
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }}
run: |
echo "${KUBE_CERT}" > ca.crt
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER}
kubectl config set-credentials deploy-user --token=${KUBE_TOKEN}
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${{ secrets.KUBE_NAMESPACE}}
kubectl config get-contexts
kubectl config use-context ${KUBE_CLUSTER}
- name: Apply the updated manifest
run: |
export APP_VERSION="${{ needs.publish_image.outputs.app_version }}"
sed -i "s/appVersionPlaceholder/${APP_VERSION}/g" kubectl_deploy/deployment.yaml
kubectl --namespace=${{ secrets.KUBE_NAMESPACE }} apply \
-f kubectl_deploy/deployment.yaml \
-f kubectl_deploy/service.yaml \
-f kubectl_deploy/ingress.yaml