Skip to content

chore(infra): Add permanent redirect to the new domain #140

chore(infra): Add permanent redirect to the new domain

chore(infra): Add permanent redirect to the new domain #140

Workflow file for this run

name: Deploy to Heroku via Docker
on:
workflow_dispatch:
push:
branches:
- main
- staging
jobs:
set_environment_name:
name: Set Environment
runs-on: ubuntu-latest
outputs:
env_name: ${{ steps.set_env.outputs.env_name }}
steps:
- id: set_env
run: echo "env_name=${{ github.ref_name == 'main' && 'production' || github.ref_name }}" >> $GITHUB_OUTPUT
deploy:
needs: [set_environment_name]
environment:
name: ${{ needs.set_environment_name.outputs.env_name }}
runs-on: ubuntu-latest
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ vars.HEROKU_APP_NAME }}
steps:
- name: πŸ›’ Checkout code
uses: actions/checkout@v3
- name: πŸ§ͺ Fetch Heroku config vars
id: heroku-vars
run: |
echo "Fetching Heroku config vars..."
response=$(curl -s -f -n -H "Authorization: Bearer $HEROKU_API_KEY" \
-H "Accept: application/vnd.heroku+json; version=3" \
https://api.heroku.com/apps/$HEROKU_APP_NAME/config-vars)
echo "DATABASE_URI=$(echo $response | jq -r '.DATABASE_URI')" >> $GITHUB_ENV
echo "PAYLOAD_SECRET=$(echo $response | jq -r '.PAYLOAD_SECRET')" >> $GITHUB_ENV
echo "PREVIEW_SECRET=$(echo $response | jq -r '.PREVIEW_SECRET')" >> $GITHUB_ENV
echo "NEXT_PUBLIC_MAPBOX_TOKEN=$(echo $response | jq -r '.NEXT_PUBLIC_MAPBOX_TOKEN')" >> $GITHUB_ENV
echo "NEXT_PUBLIC_API_URL=$(echo $response | jq -r '.NEXT_PUBLIC_API_URL')" >> $GITHUB_ENV
echo "GCS_PROJECT_ID=$(echo $response | jq -r '.GCS_PROJECT_ID')" >> $GITHUB_ENV
echo "GCS_BUCKET_NAME=$(echo $response | jq -r '.GCS_BUCKET_NAME')" >> $GITHUB_ENV
echo "GCS_SERVICE_ACCOUNT_KEY=$(echo $response | jq -r '.GCS_SERVICE_ACCOUNT_KEY')" >> $GITHUB_ENV
echo "NEXT_PUBLIC_TILER_URL=$(echo $response | jq -r '.NEXT_PUBLIC_TILER_URL')" >> $GITHUB_ENV
- name: πŸ” Log in to Heroku Container Registry
run: echo "${{ env.HEROKU_API_KEY }}" | docker login --username=_ --password-stdin registry.heroku.com
- name: πŸ— Build Docker image
run: |
docker buildx build --platform=linux/amd64 \
--build-arg PAYLOAD_SECRET=$PAYLOAD_SECRET \
--build-arg PREVIEW_SECRET=$PREVIEW_SECRET \
--build-arg DATABASE_URI=$DATABASE_URI \
--build-arg NEXT_PUBLIC_MAPBOX_TOKEN=$NEXT_PUBLIC_MAPBOX_TOKEN \
--build-arg NEXT_PUBLIC_TILER_URL=$NEXT_PUBLIC_TILER_URL \
--build-arg NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL \
--build-arg GCS_PROJECT_ID=$GCS_PROJECT_ID \
--build-arg GCS_BUCKET_NAME=$GCS_BUCKET_NAME \
--build-arg GCS_SERVICE_ACCOUNT_KEY=$GCS_SERVICE_ACCOUNT_KEY \
-t registry.heroku.com/$HEROKU_APP_NAME/web .
- name: πŸ“€ Push image to Heroku
run: docker push registry.heroku.com/$HEROKU_APP_NAME/web
- name: πŸš€ Release to Heroku
run: |
curl -n -X PATCH https://api.heroku.com/apps/$HEROKU_APP_NAME/formation \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3.docker-releases" \
-H "Authorization: Bearer $HEROKU_API_KEY" \
-d '{
"updates": [{
"type": "web",
"docker_image": "'"$(docker inspect --format={{.Id}} registry.heroku.com/$HEROKU_APP_NAME/web)"'"
}]
}'