Skip to content

Release

Release #96

Workflow file for this run

name: "Release"
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment'
required: true
default: 'dev'
jobs:
build:
runs-on: ubuntu-latest
name: Build, Push, Deploy (dev)
environment: "dev"
timeout-minutes: 45
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: docker/login-action@v3
with:
registry: ${{ vars.WS_DOCKER_REGISTRY }}
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: "Build Changelog"
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v5
with:
fromTag: "0.1"
toTag: ${{ github.sha }}
mode: "HYBRID"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Move new cache
run: |
rm -rf /tmp/.buildkit-cache
mv /tmp/.buildkit-cache-new /tmp/.buildkit-cache
- name: Build and push
run: docker compose -f docker-compose.build.yml --env-file tdei_uw.env build --push --build-arg CODE_VERSION=${CODE_VERSION}
env:
ENV: ${{ vars.ENV }}
WS_DOCKER_REGISTRY: ${{ vars.WS_DOCKER_REGISTRY }}
CODE_VERSION: ${{ github.sha }}
# passwords
WS_API_DB_PASS: ${{ secrets.WS_API_DB_PASS }}
WS_MAPBOX_ACCESS_TOKEN: ${{ secrets.WS_MAPBOX_ACCESS_TOKEN }}
WS_OSM_DB_PASS: ${{ secrets.WS_OSM_DB_PASS }}
WS_OSM_SECRET_KEY_BASE: ${{ secrets.WS_OSM_SECRET_KEY_BASE }}
WS_SMTP_PASS: ${{ secrets.WS_SMTP_PASS }}
WS_TASKS_DB_PASS: ${{ secrets.WS_TASKS_DB_PASS }}
WS_TASKS_SECRET_KEY: ${{ secrets.WS_TASKS_SECRET_KEY }}
- name: Deploy
env:
ENV: ${{ vars.ENV }}
WS_DOCKER_REGISTRY: ${{ vars.WS_DOCKER_REGISTRY }}
CODE_VERSION: ${{ github.sha }}
# machine to deploy to
AZURE_DOCKER_HOST_IP: ${{ vars.AZURE_DOCKER_HOST_IP }}
# tag to deploy
WS_DOCKER_TAG: ${{ github.sha }}
# passwords
WS_API_DB_PASS: ${{ secrets.WS_API_DB_PASS }}
WS_MAPBOX_ACCESS_TOKEN: ${{ secrets.WS_MAPBOX_ACCESS_TOKEN }}
WS_OSM_DB_PASS: ${{ secrets.WS_OSM_DB_PASS }}
WS_OSM_SECRET_KEY_BASE: ${{ secrets.WS_OSM_SECRET_KEY_BASE }}
WS_SMTP_PASS: ${{ secrets.WS_SMTP_PASS }}
WS_TASKS_DB_PASS: ${{ secrets.WS_TASKS_DB_PASS }}
WS_TASKS_SECRET_KEY: ${{ secrets.WS_TASKS_SECRET_KEY }}
run: |
mkdir -p ~/.ssh
eval `ssh-agent -s`
ssh-keyscan ${{ vars.AZURE_DOCKER_HOST_IP }} >> ~/.ssh/known_hosts
echo "${{ secrets.GH_ACTIONS_SSH_KEY }}" > ~/.ssh/github_actions
chmod 600 ~/.ssh/github_actions
ssh-add ~/.ssh/github_actions
docker context create dev --docker "host=ssh://github-actions@${{ vars.AZURE_DOCKER_HOST_IP }}"
docker context use dev
# stop all running images, remove the containers, remove the images
# why? in case we're rebuilding the image of the same commit, we want to ensure the newer image is deployed
# in case the last one was corrupted for some reason--just to avoid any questions about deployment reliability
#docker stop $(docker ps -q)
#docker rm -v $(docker ps --filter status=exited -q)
#docker rmi $(docker images -q)
# remove images no longer in use--may need disk space to pull
docker image prune -a -f
# pull new images, recreate containers
docker compose -f docker-compose.deploy.yml --env-file tdei_uw.env up -d --force-recreate --remove-orphans
# check what was deployed, just to save in the GH logs
sleep 30s
docker ps