-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (67 loc) · 3.08 KB
/
build-deploy.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
name: Build and deploy
on:
workflow_dispatch:
inputs:
name:
description: 'param1'
required: false
default: '*'
push:
branches:
- 'develop'
pull_request:
branches:
- main
- develop
jobs:
build-image:
name: build image
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Checkout infra
uses: actions/checkout@v2
with:
repository: BowellSolutions/bowell-infra
token: ${{ secrets.GH_PAT }}
path: infra_front
ref: develop
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Set buildkit pod name
id: buildkit_pod
run: echo "::set-output name=pod_name::front-buildkit-${{ github.run_number }}"
- name: Generate image's name based on tag and date
id: image_name
run: echo "::set-output name=tag::frontend:${{ steps.date.outputs.date }}_${{ github.run_number }}"
- name: Kubectl apply buildkit pod
run: |
cat infra_front/build-agents/buildkit/pod.yaml | sed "s|{{POD_NAME}}|${{ steps.buildkit_pod.outputs.pod_name }}|" | kubectl apply -f -
- name: Build image
run: |
kubectl wait --timeout=300s --for=condition=Ready pod/${{ steps.buildkit_pod.outputs.pod_name }} -n build-agents-dev
kubectl exec -n build-agents-dev ${{ steps.buildkit_pod.outputs.pod_name }} -- update-ca-certificates
kubectl cp ./ ${{ steps.buildkit_pod.outputs.pod_name }}:/tmp/bcontext -n build-agents-dev
kubectl exec -n build-agents-dev ${{ steps.buildkit_pod.outputs.pod_name }} -- buildctl \
build \
--frontend dockerfile.v0 \
--local dockerfile=. \
--local context=/tmp/bcontext \
--frontend-opt filename=tmp/bcontext/Dockerfile.prod \
--output type=image,\"name=nexus.nexus-dev.svc.cluster.local:5056/bowelsound/frontend:${{ steps.image_name.name }},nexus.nexus-dev.svc.cluster.local:5056/bowelsound/frontend:latest\",push=true \
# --export-cache type=inline \
# --import-cache type=registry,ref=nexus.nexus-dev.svc.cluster.local:5056/bowelsound/frontend:latest
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Error when generating image"
kubectl logs ${{ steps.buildkit_pod.outputs.pod_name }} -n build-agents-dev --tail 1000 && kubectl delete pod -n build-agents-dev ${{ steps.buildkit_pod.outputs.pod_name }}
exit 1
fi
kubectl delete pod -n build-agents-dev ${{ steps.buildkit_pod.outputs.pod_name }}
- name: Apply new deployment
run : |
sed "s|{{IMAGE_NAME}}|${{ steps.image_name.name }}|" infra_front/k8s_front/k8s/deployment.yaml | kubectl apply -f -
kubectl rollout restart deployment/bowelsound-frontend -n bowelsound-dev
kubectl rollout status deployment/bowelsound-frontend -n bowelsound-dev --timeout=300s