This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
161 lines (154 loc) · 5.49 KB
/
cd-master.yaml
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
155
156
157
158
159
160
161
#
# bento-box
# continuous deployment (cd) pipeline for the master branch
#
name: "CD Pipeline (Master)"
on:
push:
branches:
- master
env:
DOCKER_REPO: ghcr.io/bentobox-dev/bentobox-engine
DOCKER_BUILDKIT: 1
jobs:
# builds & publishes docs for the sdk component to Github
publish-docs-sdk:
runs-on: ubuntu-20.04
name: "Publish bentobox-sdk Docs to Github Pages"
env:
SDK_DOC_DIR: /tmp/docs
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
steps:
- uses: actions/checkout@v2
with:
# fetch all history for all branches and tags
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: 3.7
- name: "Pull dependencies"
run: |
make dep-sdk-dev
- name: "Build bentobox-sdk"
run: |
make build-sdk
- name: "Build bentobox-sdk Docs"
run: |
make build-sdk-docs SDK_DOC_DIR=${SDK_DOC_DIR}
- name: "Publish bentobox-sdk Docs to Github Pages"
run: |
git checkout gh-pages
# move generated docs to top level docs/ and stage changes
rm -rf docs
mv -f ${SDK_DOC_DIR}/bento docs
git add docs
# check for staged changes to SDK docs
if git diff --staged --quiet
then
echo "No SDK Docs changes to commit."
exit 0
fi
# Commit changes as Github Actions bot
git config user.name 'github-actions'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
GIT_REF_NAME="$(echo ${GITHUB_REF} | sed -e "s|\w*/\w*/||")"
git commit -a -m "CI: Update docs built from ${GIT_REF_NAME} commit: ${GITHUB_SHA}"
# Publish changes by pushing to Github
git push
# build and publish the engine component on github container registry
publish-engine:
runs-on: ubuntu-20.04
name: "Publish bentobox-engine container to Github Container Registry"
outputs:
container-tag: ${{ steps.resolve-tag.outputs.container-tag }}
steps:
- uses: actions/checkout@v2
with:
# fetch all history for all branches and tags
fetch-depth: 0
- id: resolve-tag
name: "Resolve bentobox-engine container tag"
run: |
DOCKER_TAG=$DOCKER_REPO:$(git describe --always)
echo $DOCKER_TAG
echo "::set-output name=container-tag::${DOCKER_TAG}"
- name: "Build bentobox-engine"
run: |
# build container tagged version given by git describe
DOCKER_TAG=${{ steps.resolve-tag.outputs.container-tag }}
make \
SIM_BUILD_TYPE=Release \
SIM_DOCKER_STAGE=release \
SIM_DOCKER_CACHE_FROM="${DOCKER_REPO}:latest" \
SIM_DOCKER=${DOCKER_TAG} \
build-sim-docker
- name: "Authenticate with Github Container Registry"
env:
GHCR_USER: ${{secrets.GHCR_USER}}
GHCR_TOKEN: ${{secrets.GHCR_TOKEN}}
run: |
echo $GHCR_TOKEN | docker login ghcr.io --username $GHCR_USER --password-stdin
- name: "Push bentobox-engine container to Github Container Registry"
run: |
# push with both latest and versioned tag
DOCKER_TAG=${{ steps.resolve-tag.outputs.container-tag }}
docker push $DOCKER_TAG
docker tag $DOCKER_TAG "${DOCKER_REPO}:latest"
docker push "${DOCKER_REPO}:latest"
# deploy the engine component on DigitalOcean K8s using the currently built image
deploy-engine:
needs: publish-engine
runs-on: ubuntu-20.04
name: "Deploy bentobox-engine on DigitalOcean k8s (bento.mrzzy.co:54242)"
env:
DIGITALOCEAN_K8S_CLUSTER: do-k8s-sg
steps:
- uses: actions/checkout@v2
# Init doctl CLI
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_TOKEN }}
# Get the kubeconfig containing the credentials required to deploy to k8s cluster
- name: Get Kubeconfig Credentials for DigitalOcean K8s Cluster
run: |
doctl kubernetes cluster kubeconfig save $DIGITALOCEAN_K8S_CLUSTER
# Install kustomize
- name: Install Kustomize
run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
chmod u+x ./kustomize
mv kustomize -t infra/kustomize/engine/
- name: Deploy bentobox-engine to DigitalOcean K8s Cluster
run: |
# apply bentobox-engine Container Tag to manfiests
DOCKER_TAG=${{ needs.publish-engine.outputs.container-tag }}
cd infra/kustomize/engine/
./kustomize edit set image bentobox-engine=$DOCKER_TAG
# show the changes made by kustomize
git diff
# deploy using kubectl
./kustomize build . | kubectl apply -f -
# build and publish the engine component on github container registry
publish-sdk:
runs-on: ubuntu-20.04
name: "Publish bentobox-sdk package to Pypi"
steps:
- uses: actions/checkout@v2
with:
# fetch all history for all branches and tags
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: 3.7
- name: "Build bentobox-sdk"
run: |
# build dist bentobox package to sdk/dist
make build-sdk
# display built artifacts
ls sdk/dist/
- name: Publish bentobox-sdk to Test PyPI
uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_TOKEN }}
packages_dir: sdk/dist/