Skip to content

- ensure image is passed into deploy command #32

- ensure image is passed into deploy command

- ensure image is passed into deploy command #32

name: Deploy and Build Docker Image and release to Heroku
on:
push:
branches: [ "fly-deploy" ]
pull_request:
branches: [ "main" ]
jobs:
deploy:
runs-on: ubuntu-latest
concurrency: deploy-group
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
# - name: Build the Docker image
# run: docker build . --build-arg CHROME_VERSION=${{ secrets.CHROME_VERSION }} --build-arg CHROMEDRIVER_VERSION=${{ secrets.CHROMEDRIVER_VERSION }} --file Dockerfile --tag ngx-ramblers:${{ github.run_number }}
#
# - name: Tag the Docker image (github run number ${{ github.run_number }})
# run: docker tag ngx-ramblers:${{ github.run_number }} ${{ secrets.DOCKER_USERNAME }}/ngx-ramblers:${{ github.run_number }}
#
# - name: Push the Docker image to Docker Hub (github run number ${{ github.run_number }})
# run: docker push ${{ secrets.DOCKER_USERNAME }}/ngx-ramblers:${{ github.run_number }}
#
# - name: Tag the Docker image (latest)
# run: docker tag ngx-ramblers:${{ github.run_number }} ${{ secrets.DOCKER_USERNAME }}/ngx-ramblers:latest
#
# - name: Push the Docker image to Docker Hub (latest)
# run: docker push ${{ secrets.DOCKER_USERNAME }}/ngx-ramblers:latest
#
# - name: Install Heroku CLI
# run: curl https://cli-assets.heroku.com/install.sh | sh
#
# - name: Log in to Heroku container registry
# run: echo "${{ secrets.HEROKU_API_KEY }}" | docker login --username="${{ secrets.HEROKU_EMAIL }}" --password-stdin registry.heroku.com
#
# - name: Tag Docker image for Heroku (github run number ${{ github.run_number }})
# run: docker tag ${{ secrets.DOCKER_USERNAME }}/ngx-ramblers:${{ github.run_number }} registry.heroku.com/ngx-ramblers-docker:${{ github.run_number }}
#
# - name: Push Docker image to Heroku (github run number ${{ github.run_number }})
# run: docker push registry.heroku.com/ngx-ramblers-docker:${{ github.run_number }}
#
# - name: Release Docker image on Heroku (github run number ${{ github.run_number }})
# run: heroku container:release ${{ github.run_number }} --app ngx-ramblers-docker
#
# - name: Tag Docker image for Heroku (latest)
# run: docker tag ${{ secrets.DOCKER_USERNAME }}/ngx-ramblers:${{ github.run_number }} registry.heroku.com/ngx-ramblers-docker:latest
#
# - name: Push Docker image to Heroku (latest)
# run: docker push registry.heroku.com/ngx-ramblers-docker:latest
#
- name: Set environment variables for fly.io deployment
run: |
echo "APP_NAME=${{ secrets.APP_NAME }}" >> $GITHUB_ENV
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> $GITHUB_ENV
echo "DOCKER_IMAGE=${{ secrets.DOCKER_USERNAME }}/ngx-ramblers:27" >> $GITHUB_ENV
echo "ALLOWED_DOMAINS=${{ secrets.ALLOWED_DOMAINS }}" >> $GITHUB_ENV # Add this line
- name: Replace Docker image, app name, and allowed domains in fly.toml
env:
APP_NAME: ${{ secrets.APP_NAME }}
DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE }}
ALLOWED_DOMAINS: ${{ secrets.ALLOWED_DOMAINS }}
run: |
sed -i 's|\${DOCKER_IMAGE}|'"$DOCKER_IMAGE"'|g' fly.toml
sed -i 's|\${APP_NAME}|'"$APP_NAME"'|g' fly.toml
sed -i 's|\${ALLOWED_DOMAINS}|'"$ALLOWED_DOMAINS"'|g' fly.toml
- name: Install Flyctl
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Deploy App
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
APP_NAME: ${{ secrets.APP_NAME }}
CHROMEDRIVER_VERSION: ${{ secrets.CHROMEDRIVER_VERSION }}
CHROME_VERSION: ${{ secrets.CHROME_VERSION }}
DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE }}
run: |
flyctl deploy --remote-only --image ${{ secrets.DOCKER_IMAGE }} --app ${{ secrets.APP_NAME }} \
--build-arg CHROME_VERSION=${{ secrets.CHROME_VERSION }} \
--build-arg CHROMEDRIVER_VERSION=${{ secrets.CHROMEDRIVER_VERSION }}
- name: Scale App to 1
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
APP_NAME: ${{ secrets.APP_NAME }}
CHROMEDRIVER_VERSION: ${{ secrets.CHROMEDRIVER_VERSION }}
CHROME_VERSION: ${{ secrets.CHROME_VERSION }}
run: flyctl scale count 1 --app $APP_NAME