How do I deploy dev to one app and master to another?

I have two apps on Fly, my-app and my-app-stage.
The application is built on Remix and I intend to push the dev branch to my-app-stage and master to my-app.
I am trying to do this using GitHub actions.
Problem is, master gets deployed to my-app via the deploy.yml action without an issue, but I created a new stage.yml action that should deploy the dev branch to my-app-stage, but it deploys to my-app as well.

Following is the relevant snippet in stage.yml

build:
    name: 🐳 Build
    # only build/deploy dev branch on workflow_dispatch
    if: ${{ (github.ref == 'refs/heads/dev') && github.event_name == 'workflow_dispatch' }}
    runs-on: ubuntu-latest
    steps:
      - name: 🛑 Cancel Previous Runs
        uses: styfle/cancel-workflow-action@0.10.0

      - name: ⬇️ Checkout repo
        uses: actions/checkout@v3

      - name: 👀 Read app name
        uses: SebRollen/toml-action@v1.0.0
        id: app_name
        with:
          file: "fly-stage.toml"
          field: "app"

      - name: 🐳 Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      # Setup cache
      - name: ⚡️ Cache Docker layers
        uses: actions/cache@v3
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-

      - name: 🔑 Fly Registry Auth
        uses: docker/login-action@v2
        with:
          registry: registry.fly.io
          username: x
          password: ${{ secrets.FLY_API_TOKEN }}

      - name: 🐳 Docker build
        uses: docker/build-push-action@v3
        with:
          context: .
          push: true
          tags: registry.fly.io/${{ steps.app_name.outputs.value }}:${{ github.ref_name }}-${{ github.sha }}
          build-args: |
            COMMIT_SHA=${{ github.sha }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

      - name: 🚚 Move cache
        run: |
          rm -rf /tmp/.buildx-cache
          mv /tmp/.buildx-cache-new /tmp/.buildx-cache

  deploy:
    name: 🚀 Deploy
    runs-on: ubuntu-latest
    needs: [lint, typecheck, vitest, build]
    # only build/deploy dev branch on workflow_dispatch
    if: ${{ (github.ref == 'refs/heads/dev') && github.event_name == 'workflow_dispatch' }}

    steps:
      - name: 🛑 Cancel Previous Runs
        uses: styfle/cancel-workflow-action@0.10.0

      - name: ⬇️ Checkout repo
        uses: actions/checkout@v3

      - name: 👀 Read app name
        uses: SebRollen/toml-action@v1.0.0
        id: app_name
        with:
          file: "fly-stage.toml"
          field: "app"

      - name: 🚀 Deploy Stage
        if: ${{ github.ref == 'refs/heads/dev' }}
        uses: superfly/flyctl-actions@1.3
        with:
          args: "deploy --image registry.fly.io/${{ steps.app_name.outputs.value }}:${{ github.ref_name }}-${{ github.sha }}"
        env:
          FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

And my fly-stage.toml looks like this

app = "study-in-china-webapp-stage"
kill_signal = "SIGINT"
kill_timeout = 5
processes = [ ]

[experimental]
allowed_public_ports = [ ]
auto_rollback = true
cmd = "start.sh"
entrypoint = "sh"

[mounts]
source = "data"
destination = "/data"

[[services]]
internal_port = 8_080
processes = [ "app" ]
protocol = "tcp"
script_checks = [ ]

  [services.concurrency]
  hard_limit = 25
  soft_limit = 20
  type = "connections"

  [[services.ports]]
  handlers = [ "http" ]
  port = 80
  force_https = true

  [[services.ports]]
  handlers = [ "tls", "http" ]
  port = 443

  [[services.tcp_checks]]
  grace_period = "1s"
  interval = "15s"
  restart_limit = 0
  timeout = "2s"

  [[services.http_checks]]
  interval = "10s"
  grace_period = "5s"
  method = "get"
  path = "/healthcheck"
  protocol = "http"
  timeout = "2s"
  tls_skip_verify = false
  headers = { }

Any help is appreciated.

You can override the app name by using the --app option so when you deploy from your Dev branch you can specify --app my-app-stage and when you deploy from master you can specify --app my-app.

2 Likes

This worked. Thanks a lot.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.