Merge pull request #17 from terrateamio/pro-368-fix-build #14
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: production-app-build-deploy | |
on: | |
push: | |
branches: | |
- "main" | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and deploy | |
env: | |
DOCKER_BUILDKIT: 1 | |
MATRIX_PASSWORD: ${{ secrets.MATRIX_PASSWORD }} | |
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} | |
TERRATEAM_SELF_HOSTED_BUILD_GH_TOKEN: ${{ secrets.TERRATEAM_SELF_HOSTED_BUILD_GH_TOKEN }} | |
TERRATEAM_ENVIRONMENT: "production" | |
TERRATEAM_POSTHOG_TOKEN: ${{ vars.TERRATEAM_POSTHOG_TOKEN }} | |
run: | | |
curl -L https://fly.io/install.sh | sh | |
/home/runner/.fly/bin/flyctl deploy -a terrateam-app-$TERRATEAM_ENVIRONMENT --dockerfile docker/terrat/Dockerfile --build-arg TERRAT_UI_ANALYTICS=$TERRATEAM_POSTHOG_TOKEN --build-arg BASE_IMAGE="registry.fly.io/terrateam-app-$TERRATEAM_ENVIRONMENT:base" | |
MATRIX_ACCESS_TOKEN=$(curl -s -XPOST -d '{"type":"m.login.password", "user":"terrateam", "password":'\"$MATRIX_PASSWORD\"'}' "https://matrix.org/_matrix/client/r0/login" | grep -Po '"access_token":.*?[^\\]",' | cut -d'"' -f4) | |
MATRIX_MESSAGE="GitHub Actions [$GITHUB_WORKFLOW]: Deployed $GITHUB_SHA" | |
curl 'https://matrix.org/_matrix/client/r0/rooms/!AJlEMsztoOToHdwijN%3Amatrix.org/send/m.room.message/?access_token='$MATRIX_ACCESS_TOKEN -X PUT --data '{"msgtype":"m.text","body":"'"$MATRIX_MESSAGE"'"}' | |
/home/runner/.fly/bin/flyctl auth docker | |
DEPLOYMENT_TAG=$(/home/runner/.fly/bin/flyctl image show -a terrateam-app-$TERRATEAM_ENVIRONMENT | grep deployment | awk '{print $4}' | sort | uniq) | |
docker pull "registry.fly.io/terrateam-app-$TERRATEAM_ENVIRONMENT:$DEPLOYMENT_TAG" | |
docker tag "registry.fly.io/terrateam-app-$TERRATEAM_ENVIRONMENT:$DEPLOYMENT_TAG" ghcr.io/terrateamio/terrateam:v1 | |
docker push ghcr.io/terrateamio/terrateam:v1 |