-
Notifications
You must be signed in to change notification settings - Fork 1
89 lines (82 loc) · 3.1 KB
/
pages.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
name: Build and Deploy
on: [push]
env:
#variables related with the repository
REPOSITORY_MAIN_BRANCH: "master"
#variables related with the docker imager registry
DOCKER_IMAGE_REPOSITORY: ikcap
DOCKER_IMAGE_NAME: disk-website
#variables related with the continuous delivery
MANIFEST_REPOSITORY: KnowledgeCaptureAndDiscovery/k8s
MANIFEST_REPOSITORY_BRANCH: master
MANIFEST_REPOSITORY_PATH: disk-server/disk/website
KUSTOMIZE_IMAGE_NAME: website
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Create value as an environment variable
run: |
echo "DOCKER_TAG=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Expose value
id: exposeValue
run: |
echo "::set-output name=docker_tag::${{ env.DOCKER_TAG }}"
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/[email protected]
if: github.event_name != 'pull_request'
with:
push: true
context: .
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_TAG }},${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }}:latest
file: ${{ env.DOCKER_FILE}}
outputs:
docker_tag: ${{ steps.exposeValue.outputs.docker_tag }}
update:
# This job the container running on k8s cluster
needs: [build]
name: "Deploy the app"
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-latest
steps:
- name: Check out k8s manifests
uses: actions/checkout@v3
if: github.event_name != 'pull_request'
with:
repository: ${{ env.MANIFEST_REPOSITORY }}
ref: ${{ env.MANIFEST_REPOSITORY_BRANCH }}
ssh-key: ${{ secrets.BOT_SSH }}
persist-credentials: true
- name: Setup Kustomize
uses: imranismail/setup-kustomize@v1
if: github.event_name != 'pull_request'
with:
kustomize-version: "3.6.1"
- name: Update Kubernetes resources
if: github.event_name != 'pull_request'
run: |
cd ${{ env.MANIFEST_REPOSITORY_PATH }}
kustomize edit set image ${{ env.KUSTOMIZE_IMAGE_NAME }}=${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.build.outputs.docker_tag }}
cat kustomization.yaml
- name: Commit files
if: github.event_name != 'pull_request'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git commit -am "Disk web updated"
- name: Push changes
if: github.event_name != 'pull_request'
uses: ad-m/github-push-action@master
with:
ssh: true
branch: ${{ env.MANIFEST_REPOSITORY_BRANCH }}
repository: ${{ env.MANIFEST_REPOSITORY }}