Azure / container-apps-deploy-action

GitHub Action for building and deploying Azure Container Apps
MIT License
50 stars 30 forks source link

Passing env variables to docker build #8

Open georgibakken opened 1 year ago

georgibakken commented 1 year ago

Hi there,

I am trying to use the container-apps-adeploy-action for a nextjs application, specifically Tina.io.

Tina requires three env variables to be set when building, which I locally set in a .env with the variables NEXT_PUBLIC_TINA_CLIENT_ID, TINA_TOKEN and NEXT_PUBLIC_TINA_BRANCH. This work nicely locally when I build the docker image.

In my GitHub action, I set them under env and read from GitHub secret. This is my workflow file:

name: Azure Container App CI/CD
on:
  push:
    branches:
      - main
env:
  NEXT_PUBLIC_TINA_CLIENT_ID: ${{ secrets.NEXT_PUBLIC_TINA_CLIENT_ID }}
  TINA_TOKEN: ${{ secrets.TINA_TOKEN }}
  NEXT_PUBLIC_TINA_BRANCH: main
jobs:
  build_and_deploy_job:
    runs-on: ubuntu-latest
    name: Build and deploy job
    steps:
      - uses: actions/checkout@v3

      - name: Log in to Azure
        uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}

      - name: Build and deploy Container App
        uses: azure/container-apps-deploy-action@v0
        with:
          appSourcePath: ${{ github.workspace }}
          acrName: KoermitApiRegistry
          acrUsername: ${{ secrets.REGISTRY_USERNAME }}
          acrPassword: ${{ secrets.REGISTRY_PASSWORD }}
          containerAppName: tina-handbook
          resourceGroup: tina-lab-handbook
          containerAppEnvironment: labs-handbook
          dockerfilePath: Dockerfile

However I get an error from the action build job Error: Client not configured properly. Missing branch, clientId, token. Please visit https://tina.io/docs/tina-cloud/connecting-site/ for more information

These values are set from the env variables NEXT_PUBLIC_TINA_CLIENT_ID, TINA_TOKEN and NEXT_PUBLIC_TINA_BRANCH.

Another log from the action, is this:

Run docker build --tag KoermitApiRegistry.azurecr.io/github-action/container-app:3550347084.1 --file /home/runner/work/tina-labs-handbook/tina-labs-handbook/Dockerfile /home/runner/work/tina-labs-handbook/tina-labs-handbook
[275](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:290)
  docker build --tag KoermitApiRegistry.azurecr.io/github-action/container-app:3550347084.1 --file /home/runner/work/tina-labs-handbook/tina-labs-handbook/Dockerfile /home/runner/work/tina-labs-handbook/tina-labs-handbook
[276](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:291)
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail ***0***
[277](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:292)
  env:
[278](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:293)
    NEXT_PUBLIC_TINA_CLIENT_ID: ***
[279](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:294)
    TINA_TOKEN: ***
[280](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:295)
    NEXT_PUBLIC_TINA_BRANCH: main
[281](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:296)
    AZURE_HTTP_USER_AGENT: 
[282](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:297)
    AZUREPS_HOST_ENVIRONMENT: 
[283](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:298)
    CA_GH_ACTION_ACR_LOGIN_ARG: --registry-server KoermitApiRegistry.azurecr.io --registry-username *** --registry***
[284](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:299)
    CA_GH_ACTION_DOCKERFILE_PATH: /home/runner/work/tina-labs-handbook/tina-labs-handbook/Dockerfile
[285](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:300)
    CA_GH_ACTION_IMAGE_TO_BUILD: KoermitApiRegistry.azurecr.io/github-action/container-app:3550347084.1
[286](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:301)
    CA_GH_ACTION_IMAGE_TO_DEPLOY: KoermitApiRegistry.azurecr.io/github-action/container-app:3550347084.1
[287](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:302)
    CA_GH_ACTION_RESOURCE_GROUP: tina-lab-handbook
[288](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:303)
    CA_GH_ACTION_CONTAINER_APP_ENVIRONMENT_ARG: --environment labs-handbook
[289](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:304)
    CA_GH_ACTION_RUNTIME_STACK: node:16
[290](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:305)
    CA_GH_ACTION_TARGET_PORT: 
[291](https://github.com/DanskeStatsbaner/tina-labs-handbook/actions/runs/3550347084/jobs/5963640559#step:4:307)
Sending build context to Docker daemon  1.143MB

Based on this, it looks as for me that the deploy action passes the correct env variables to docker, they are set and as far as I understand should be ready for docker build to read. Which is why I don't understand why the application throws the errors that the variables are not set/not configured.

Any ideas on what is going wrong? Thank you!

cormacpayne commented 1 year ago

@georgibakken Hey Georg -- apologies for the delayed response; the above issue is an interesting one 🤔 Do you possibly have a past workflow where you ran docker build against the Dockerfile in your repository that was successful? Maybe just a simple workflow that directly calls the command that's being executed within container-apps-deploy-action:

docker build --tag KoermitApiRegistry.azurecr.io/github-action/container-app:3550347084.1 --file /home/runner/work/tina-labs-handbook/tina-labs-handbook/Dockerfile /home/runner/work/tina-labs-handbook/tina-labs-handbook

(you can tweak the tags and paths to get it to work)

I'm interested in comparing the logs that are produced from this successful run within a GitHub Actions workflow and the logs that you provided above that showed some of the steps being performed by container-apps-deploy-action. As you mentioned, the environment variables set in your workflow specific to Tina.io are correctly propagated to the action, and you're using a Dockerfile and not our builder, so another container is not involved in this process (as far as I can tell), so some initial logs for comparison may help shed a little light if you're able to provide them whenever you have a chance to do so. Thanks!