pin the image a bit more #618
Workflow file for this run
This file contains hidden or 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: Test and Build image | |
| on: | |
| push: | |
| tags: | |
| - "[0-9]+.[0-9]+.[0-9]+" | |
| - '[0-9]+.[0-9]+.[0-9]+-rc\.[0-9]+' | |
| branches: | |
| - "*" | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| container: | |
| # Pinned to just before an error, TODO: upgrade | |
| image: elixir:1.18.3-alpine | |
| services: | |
| postgres: | |
| image: postgres:14 | |
| env: | |
| POSTGRES_USER: pr_user | |
| POSTGRES_PASSWORD: 1234 | |
| POSTGRES_DB: postgres | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - name: Install APK packages | |
| run: | | |
| apk update | |
| apk add --virtual build-dependencies build-base | |
| apk add bash nodejs npm inotify-tools openssl | |
| - uses: actions/checkout@v1 | |
| - name: Install Dependencies | |
| run: | | |
| mix local.hex --force | |
| mix local.rebar --force | |
| mix deps.get | |
| - name: Run Tests | |
| run: mix test | |
| env: | |
| # use postgres for the host here because we have specified a container for the job. | |
| # If we were running the job on the VM this would be localhost | |
| POSTGRES_HOST: postgres | |
| POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} | |
| check_tag: | |
| name: Check tag | |
| runs-on: ubuntu-latest | |
| outputs: | |
| deploy_staging: ${{ steps.check-tag.outputs.deploy_staging }} | |
| deploy_production: ${{ steps.check-tag.outputs.deploy_production }} | |
| tags: ${{ steps.check-tag.outputs.tags }} | |
| steps: | |
| - name: Check tag ${{ github.ref }} | |
| id: check-tag | |
| run: | | |
| if [[ ${{ github.ref }} =~ refs\/tags\/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "deploy_production=true" >> $GITHUB_OUTPUT | |
| echo "tags=latest,${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "deploy_production=false" >> $GITHUB_OUTPUT | |
| fi | |
| if [[ ${{ github.ref }} =~ refs\/tags\/[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+ ]]; then | |
| echo "deploy_staging=true" >> $GITHUB_OUTPUT | |
| echo "tags=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "deploy_staging=false" >> $GITHUB_OUTPUT | |
| fi | |
| release: | |
| name: Release Docker image | |
| runs-on: ubuntu-latest | |
| needs: [check_tag, test] | |
| if: startsWith(github.ref, 'refs/tags/') | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v1 | |
| - name: Publish to Registry | |
| uses: elgohr/Publish-Docker-Github-Action@master | |
| env: | |
| APP_REVISION: ${{ github.ref_name }} | |
| with: | |
| name: errkk/playrequest/pr | |
| username: _ | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| registry: ghcr.io | |
| dockerfile: Dockerfile | |
| buildargs: APP_REVISION | |
| tags: ${{ needs.check_tag.outputs.tags }} | |
| deploy_prod: | |
| name: Deploy production | |
| runs-on: ubuntu-latest | |
| needs: [check_tag, release] | |
| if: needs.check_tag.outputs.deploy_production == 'true' | |
| env: | |
| FLY_APP: sonosnow | |
| FLY_ACCESS_TOKEN: ${{ secrets.FLY_ACCESS_TOKEN }} | |
| GITHUB_TOKEN: ${{ github.token }} | |
| FLYCTL_INSTALL: /home/runner/.fly | |
| steps: | |
| - name: Install Fly | |
| run: curl -L https://fly.io/install.sh | sh | |
| - name: Create deployment (Prod) | |
| uses: niklasmerz/github-deployment-action@master | |
| with: | |
| args: -o errkk -r playrequest -c master -e production | |
| - name: Deploy to Production | |
| run: | | |
| export PATH="$FLYCTL_INSTALL/bin:$PATH" | |
| flyctl deploy --config fly.prod.toml --image ghcr.io/errkk/playrequest/pr:${{ github.ref_name }} | |
| - name: Mark successful deployment | |
| if: success() | |
| uses: niklasmerz/github-deployment-action@master | |
| with: | |
| args: -o errkk -r playrequest -s success -u https://sonosnow.fly.dev -f | |
| deploy_staging: | |
| name: Deploy staging | |
| runs-on: ubuntu-latest | |
| needs: [check_tag, release] | |
| if: needs.check_tag.outputs.deploy_staging == 'true' | |
| env: | |
| FLY_APP: sonosnow-staging | |
| FLY_ACCESS_TOKEN: ${{ secrets.FLY_ACCESS_TOKEN }} | |
| GITHUB_TOKEN: ${{ github.token }} | |
| FLYCTL_INSTALL: /home/runner/.fly | |
| steps: | |
| - name: Install Fly | |
| run: curl -L https://fly.io/install.sh | sh | |
| - name: Create deployment (Staging) | |
| uses: niklasmerz/github-deployment-action@master | |
| with: | |
| args: -o errkk -r playrequest -c master -e staging | |
| - name: Deploy to Staging | |
| run: | | |
| export PATH="$FLYCTL_INSTALL/bin:$PATH" | |
| flyctl deploy --config fly.staging.toml --image ghcr.io/errkk/playrequest/pr:${{ github.ref_name }} | |
| - name: Mark successful deployment | |
| if: success() | |
| uses: niklasmerz/github-deployment-action@master | |
| with: | |
| args: -o errkk -r playrequest -s success -u https://sonosnow-staging.fly.dev -f |