simplify article process; move readable names to models #299
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |