forked from omegaup/omegaup
-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (86 loc) · 3.98 KB
/
build-containers.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
name: Build containers
on:
push:
branches:
- main
- release
jobs:
deploy:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Build docker containers
env:
COMPOSE_DOCKER_CLI_BUILD: 1
DOCKER_BUILDKIT: 1
TAG: ${{ github.sha }}
run: |
docker compose --file=docker-compose.k8s.yml build \
--build-arg BRANCH=${{ steps.extract_branch.outputs.branch }} \
frontend \
frontend-sidecar \
nginx \
php
- name: Push containers to GitHub registry
run: |
echo "${{ github.token }}" | \
docker login https://docker.pkg.github.com "--username=${{ github.actor }}" --password-stdin
for container in frontend frontend-sidecar nginx php; do
for tag in "latest-${{ steps.extract_branch.outputs.branch }}" "${{ github.sha }}"; do
container_name="docker.pkg.github.com/${{ github.repository }}/${container}:${tag}"
docker tag "omegaup/${container}:${{ github.sha }}" "${container_name}"
docker push "${container_name}"
done
done
- name: Push containers to Docker registry
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | \
docker login "--username=${{ secrets.DOCKER_USERNAME }}" --password-stdin
for container in frontend frontend-sidecar nginx php; do
docker push "omegaup/${container}:${{ github.sha }}"
container_name="omegaup/${container}:latest-${{ steps.extract_branch.outputs.branch }}"
docker tag "omegaup/${container}:${{ github.sha }}" "${container_name}"
docker push "${container_name}"
done
- name: Update k8s sandbox manifests
if: ${{ github.ref == 'refs/heads/main' }}
run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
sudo mv kustomize /usr/local/bin/
git clone --depth=1 https://omegaup-bot:${{ secrets.OMEGAUPBOT_RELEASE_TOKEN }}@github.com/omegaup/prod /tmp/prod
TAG=${{ github.sha }}
(cd /tmp/prod/k8s/omegaup/overlays/sandbox/frontend &&
git config --local user.name "omegaup-bot" && \
git config --local user.email "omegaup-bot@users.noreply.github.com" && \
kustomize edit set image \
omegaup/php:${TAG} \
omegaup/nginx:${TAG} \
omegaup/frontend:${TAG} \
omegaup/frontend-sidecar:${TAG} &&
sed -i "s/app.kubernetes.io\/version: .*/app.kubernetes.io\/version: ${TAG}/" frontend-deployment.yaml &&
git commit -am "omegaUp sandbox release ${TAG}" &&
git push)
rm -rf /tmp/prod
- name: Update k8s manifests
if: ${{ github.ref == 'refs/heads/release' }}
run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
sudo mv kustomize /usr/local/bin/
git clone --depth=1 https://omegaup-bot:${{ secrets.OMEGAUPBOT_RELEASE_TOKEN }}@github.com/omegaup/prod /tmp/prod
TAG=${{ github.sha }}
(cd /tmp/prod/k8s/omegaup/overlays/production/frontend &&
git config --local user.name "omegaup-bot" && \
git config --local user.email "omegaup-bot@users.noreply.github.com" && \
kustomize edit set image \
omegaup/php:${TAG} \
omegaup/nginx:${TAG} \
omegaup/frontend:${TAG} \
omegaup/frontend-sidecar:${TAG} &&
sed -i "s/app.kubernetes.io\/version: .*/app.kubernetes.io\/version: ${TAG}/" frontend-deployment.yaml &&
git commit -am "omegaUp production release ${TAG}" &&
git push)
rm -rf /tmp/prod