Merge pull request #59 from ATOR-Development/leggo/phase-1/dev #95
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: Release New Version | |
on: | |
push: | |
branches: | |
- main | |
- 'dev_*' | |
tags: | |
- "v*" | |
env: | |
IMAGE_NAME: ator-relay-dashboard | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up environment variables | |
run: echo "NUXT_PUBLIC_COMMIT_HASH=${{ github.sha }}" >> $GITHUB_ENV | |
- name: Build image | |
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" --build-arg NUXT_PUBLIC_COMMIT_HASH=${{ github.sha }} | |
- name: Log in to registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | |
- name: Push image | |
run: | | |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
# Strip git ref prefix from version | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# Strip "v" prefix from tag name | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
# Use Docker `latest` tag convention | |
[ "$VERSION" == "main" ] && VERSION=stage | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
echo -e "{\"deploy\":\"$VERSION\",\"commit_sha\":\"${GITHUB_SHA}\"}" > deploy-vars.json | |
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION | |
- name: Deploy new version | |
env: | |
NOMAD_CACERT: operations/admin-ui-ca.crt | |
NOMAD_TOKEN: ${{ secrets.DASHBOARD_NOMAD_TOKEN }} | |
NOMAD_ADDR: ${{ secrets.NOMAD_ADDR }} | |
CONSUL_CACERT: operations/admin-ui-ca.crt | |
CONSUL_HTTP_TOKEN: ${{ secrets.DASHBOARD_CONSUL_HTTP_TOKEN }} | |
CONSUL_ADDR: ${{ secrets.CONSUL_ADDR }} | |
run: | | |
curl -L https://releases.hashicorp.com/levant/0.3.2/levant_0.3.2_linux_amd64.zip -o levant.zip | |
unzip levant.zip | |
[[ -n $(grep "dev" deploy-vars.json) ]] && ./levant render -var-file="deploy-vars.json" -consul-address=$CONSUL_ADDR -out runtime-job.hcl operations/deploy-dashboard-dev.hcl | |
[[ -n $(grep "stage" deploy-vars.json) ]] && ./levant render -var-file="deploy-vars.json" -consul-address=$CONSUL_ADDR -out runtime-job.hcl operations/deploy-dashboard-stage.hcl | |
[[ -z $(grep "stage" deploy-vars.json) && -z $(grep "dev" deploy-vars.json) ]] && ./levant render -var-file="deploy-vars.json" -consul-address=$CONSUL_ADDR -out runtime-job.hcl operations/deploy-dashboard-live.hcl | |
curl -L https://releases.hashicorp.com/nomad/1.5.6/nomad_1.5.6_linux_amd64.zip -o nomad.zip | |
unzip nomad.zip | |
./nomad job run runtime-job.hcl |