-
Notifications
You must be signed in to change notification settings - Fork 6
154 lines (149 loc) · 5.53 KB
/
styleguide.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: Style guide
on:
pull_request:
types: [labeled, opened, synchronize, reopened]
push:
branches:
- 'master'
paths-ignore:
- 'packages/contentful/**'
env:
DOCKER_REPOSITORY: europeana/styleguide
jobs:
metadata:
if: (github.event_name == 'push' && github.event.ref == 'refs/heads/master') || contains(github.event.pull_request.labels.*.name, 'styleguide')
runs-on: ubuntu-latest
outputs:
git-master-push: ${{ steps.git-master-push.outputs.status }}
git-pr-labeled: ${{ steps.git-pr-labeled.outputs.status }}
docker-labels: ${{ steps.docker.outputs.labels }}
docker-tags: ${{ steps.docker.outputs.tags }}
docker-version: ${{ steps.docker.outputs.version }}
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Git metadata, master push
id: git-master-push
if: github.event_name == 'push' && github.event.ref == 'refs/heads/master'
run: echo "status=true" >> $GITHUB_OUTPUT
-
name: Git metadata, PR labeled
id: git-pr-labeled
if: contains(github.event.pull_request.labels.*.name, 'styleguide')
run: echo "status=true" >> $GITHUB_OUTPUT
-
name: Docker metadata
id: docker
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKER_REPOSITORY }}
tags: |
type=ref,event=pr
type=ref,event=branch
docker-build:
if: needs.metadata.outputs.git-master-push == 'true' || needs.metadata.outputs.git-pr-labeled == 'true'
runs-on: ubuntu-latest
needs: [metadata]
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./styleguide/Dockerfile
pull: true
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ needs.metadata.outputs.docker-tags }}
labels: ${{ needs.metadata.outputs.docker-labels }}
deploy-ibm-cloud:
runs-on: ubuntu-latest
needs: [metadata, docker-build]
env:
IBMCLOUD_API_KEY: ${{ secrets.IBMCLOUD_API_KEY }}
IBMCLOUD_API_URL: ${{ vars.IBMCLOUD_API_URL }}
IBMCLOUD_CLUSTER_NAME: ${{ vars.IBMCLOUD_CLUSTER_NAME }}
IBMCLOUD_REGION: ${{ vars.IBMCLOUD_REGION }}
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set image tag for deployment
run: echo "DOCKER_IMAGE_TAG=${{ env.DOCKER_REPOSITORY }}:${{ needs.metadata.outputs.docker-version }}" >> $GITHUB_ENV
-
name: Prepare env for internal namespace
if: needs.metadata.outputs.git-master-push == 'true'
run: |
echo "K8S_NAMESPACE=internal" >> $GITHUB_ENV
echo "K8S_RESOURCE_NAME=styleguide" >> $GITHUB_ENV
echo "K8S_INGRESS_HOST=styleguide.eanadev.org" >> $GITHUB_ENV
-
name: Prepare env for dev namespace
if: needs.metadata.outputs.git-pr-labeled == 'true'
run: |
echo "K8S_NAMESPACE=dev" >> $GITHUB_ENV
echo "K8S_RESOURCE_NAME=styleguide-${{ needs.metadata.outputs.docker-version }}" >> $GITHUB_ENV
echo "K8S_INGRESS_HOST=${{ needs.metadata.outputs.docker-version }}.styleguide.dev.eanadev.org" >> $GITHUB_ENV
-
name: Create K8s resource manifests
run: |
envsubst < .github/workflows/support/styleguide/k8s/deployment.yml > deployment.yml
envsubst < .github/workflows/support/styleguide/k8s/service.yml > service.yml
envsubst < .github/workflows/support/styleguide/k8s/ingress.yml > ingress.yml
-
name: Install ibmcloud CLI
run: |
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
ibmcloud plugin install container-service
-
name: Login to IBM Cloud
run: |
ibmcloud login -a ${IBMCLOUD_API_URL} -r ${IBMCLOUD_REGION} --apikey ${IBMCLOUD_API_KEY}
ibmcloud ks cluster config --cluster ${IBMCLOUD_CLUSTER_NAME}
-
name: Detect new deployment
if: needs.metadata.outputs.git-pr-labeled == 'true'
run: |
set +e
kubectl --namespace ${K8S_NAMESPACE} get deployment ${K8S_RESOURCE_NAME}
if [ $? -eq 1 ]; then K8S_NEW_DEPLOYMENT="true"; else K8S_NEW_DEPLOYMENT="false"; fi
set -e
echo K8S_NEW_DEPLOYMENT=${K8S_NEW_DEPLOYMENT} >> $GITHUB_ENV
-
name: Apply resource manifests to K8s
if: needs.metadata.outputs.git-pr-labeled == 'true'
run: |
kubectl apply -f deployment.yml
kubectl apply -f service.yml
kubectl apply -f ingress.yml
-
name: Restart deployment
run: kubectl rollout restart --namespace ${K8S_NAMESPACE} deployment/${K8S_RESOURCE_NAME}
-
name: Comment with deployment link on pull request
if: env.K8S_NEW_DEPLOYMENT == 'true'
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Style guide deployment: https://${process.env.K8S_INGRESS_HOST}/`
})