-
Notifications
You must be signed in to change notification settings - Fork 258
116 lines (102 loc) · 4.51 KB
/
build_docker.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
name: "Build Docker Image"
on:
push:
branches:
- "master"
- "dev"
- "dev_v3"
workflow_dispatch:
inputs:
canarytokens-docker-branch:
description: "Branch of the canarytokens-docker repo to pull for build. Defaults to master"
required: false
jobs:
build:
runs-on: ubuntu-20.04
env:
COPYFILE_DISABLE: 1
steps:
# Checkout canarytokens-docker repo. This lands in ./canarytokens-docker
- name: Set canarytokens-docker-branch
run: |
BRANCH=$(if [ -z "${{ github.event.inputs.canarytokens-docker-branch}}" ]; then echo "master"; else echo "${{ github.event.inputs.canarytokens-docker-branch }}"; fi)
echo "CANARYTOKENS_DOCKER_BRANCH=$BRANCH" >> $GITHUB_ENV
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
with:
repository: thinkst/canarytokens-docker
path: canarytokens-docker
ref: ${{ env.CANARYTOKENS_DOCKER_BRANCH }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Fixup the build branch
run: |
sed -i'' "s/master/${GITHUB_REF##*/}/g" /home/runner/work/canarytokens/canarytokens/canarytokens-docker/canarytokens/Dockerfile
sed -i'' "s/_COMMIT_HASH_/${GITHUB_SHA##*/}/g" /home/runner/work/canarytokens/canarytokens/canarytokens-docker/canarytokens/Dockerfile
echo "Building for ${GITHUB_REF##*/}"
cat /home/runner/work/canarytokens/canarytokens/canarytokens-docker/canarytokens/Dockerfile
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
thinkst/canarytokens
tags: |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
context: /home/runner/work/canarytokens/canarytokens/canarytokens-docker/canarytokens
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
CACHE_BUSTER_COMMIT=${{ github.sha }}
dev-deploy:
if: github.repository == 'thinkst/canarytokens' && github.ref == 'refs/heads/dev_v3'
runs-on: [self-hosted, dev]
needs: build
steps:
- name: Deploy to dev machine
run: |
cd /home/ubuntu/canarytokens-scripts/
./canarytokensdb_s3backup.sh
cd /home/ubuntu/canarytokens-docker
sed "s/thinkst\/canarytokens:dev_v3/thinkst\/canarytokens:${GITHUB_REF##*/}/g" docker-compose-v3-letsencrypt.yml.tpl > docker-compose-v3-letsencrypt.yml
sed -i'' "s/CANARY_DEV_BUILD_ID=.*/CANARY_DEV_BUILD_ID=${GITHUB_SHA:0:8}/" frontend.env
sudo docker pull thinkst/canarytokens:${GITHUB_REF##*/}
sudo docker compose -f docker-compose-v3-letsencrypt.yml pull
sudo docker compose -f docker-compose-v3-letsencrypt.yml down
sudo docker compose -f docker-compose-v3-letsencrypt.yml up -d
sudo docker system prune -f -a
staging-deploy:
if: github.repository == 'thinkst/canarytokens' && github.ref == 'refs/heads/master'
runs-on: [self-hosted, staging]
needs: build
steps:
- name: Deploy to staging machine
run: |
cd /home/ubuntu/canarytokens-scripts/
./canarytokensdb_s3backup.sh
cd /home/ubuntu/canarytokens-docker
sed "s/thinkst\/canarytokens:dev/thinkst\/canarytokens:${GITHUB_REF##*/}/g" docker-compose-v3-letsencrypt.yml.tpl > docker-compose-v3-letsencrypt.yml
sed -i'' "s/CANARY_DEV_BUILD_ID=.*/CANARY_DEV_BUILD_ID=${GITHUB_SHA:0:8}/" frontend.env
sudo docker pull thinkst/canarytokens:${GITHUB_REF##*/}
sudo docker compose -f docker-compose-v3-letsencrypt.yml pull
sudo docker compose -f docker-compose-v3-letsencrypt.yml down
sudo docker compose -f docker-compose-v3-letsencrypt.yml up -d
sudo docker system prune -f -a