简体   繁体   English

Github 操作工作流到 docker 容器环境

[英]Github actions workflow to docker container environment

I have the following environment variable set in GitHub workflow file (on the top level):我在 GitHub 工作流文件中设置了以下环境变量(在顶层):

env: 
  GITHUB_RUN_NUMBER: ${github.run_number}

I would like to access it in my docker container (frontend-react) and log in console:我想在我的 docker 容器(前端反应)中访问它并登录控制台:

console.log(`Build number= ${process.env.GITHUB_RUN_NUMBER}`)

Currently, the GITHUB_RUN_NUMBER does not reach the container build in the workflow exec container env目前,GITHUB_RUN_NUMBER 未达到工作流exec container env环境中的容器构建

How should I pass environment variables from workflow to container?我应该如何将环境变量从工作流传递到容器? Thanks!谢谢!

name: CI_DEMO

on:

  workflow_dispatch
    
env: 
  GITHUB_RUN_NUMBER: ${github.run_number}
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

  Test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '14.20.1'
          cache: 'npm'
      - run: npm ci
      - run: CI=true npm test -- --verbose --coverage --watchAll=false

  Build_Demo:
    runs-on: ubuntu-latest
    needs: [ Test ]
    steps:
      - uses: actions/checkout@v3
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID  }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: eu-central-1
      - name: Login to Amazon ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v1
      - name: Build and Push Docker Image
        env:
          CI_COMMIT_TAG: N-${{ github.run_number }}
        run: |
          sudo docker build -t $CI_REGISTRY/$CI_REGISTRY_REPOSITORY:$CI_COMMIT_TAG . \
            -f ./deploy/Dockerfile \
            --build-arg WEB_PRIVATE_KEY="$WEB_PRIVATE_KEY" \
            --build-arg REACT_APP_GA_TRACKING_ID=$REACT_APP_GA_TRACKING_ID \
            --build-arg 
          docker push $CI_REGISTRY/$CI_REGISTRY_REPOSITORY:$CI_COMMIT_TAG

  Deploy_Demo:
    runs-on: ubuntu-latest
    needs: [ Build_NIX_Demo ]
    steps:
      - uses: actions/checkout@v3
      - name: Preparing for deploy
        env:
          DEMO_PRIVATE_KEY: ${{ secrets.DEMO_PRIVATE_KEY }}
        run: |
          
      - name: Deploy
        env:
          
        run: |
          
          export TMP_AFRONTEND_VERSION=$CI_COMMIT_TAG
          ssh -o SendEnv=TMP_AFRONTEND_VERSION  $DEMO_IP "AFRONTEND_VERSION=$TMP_AFRONTEND_VERSION; unset AFRONTEND_VERSION; export AFRONTEND_VERSION; docker-compose -f $DEMO_PROJECT_PATH/docker-compose.yml --env-file $DEMO_PROJECT_PATH/.env up -d --no-deps a_frontend"

The missing step was defining the variable in Docker file as mentioned by aknosisaknosis所述,缺少的步骤是在 Docker 文件中定义变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在私有 docker 容器中运行整个 GitHub 操作工作流作业 - Run entire GitHub Actions workflow job in private docker container Vuejs 到 Github Actions 中的 docker 容器 - Vuejs to docker container in Github Actions 如何在 GitHub Actions 中失败时重新运行 docker 容器,但工作流仍然通过? - How to rerun a docker container on failure in GitHub Actions, but still have the workflow pass? Github 将容器推送到 Github 容器注册表的操作工作流程失败并显示“未经身份验证” - Github Actions workflow for pushing a container to Github Container Registry fails with "unauthenticated" 具有数据库依赖性的 Docker Github 工作流:没有这样的容器 - Docker Github workflow with database dependency: No such container 使用 Compose 和 Github 操作部署 Docker 容器 - Deploy Docker Container with Compose & Github Actions 在容器中运行步骤时,Github Actions工作流程失败 - Github Actions workflow fails when running steps in a container docker 在 Github 上运行 dynamodb-local 操作工作流挂起 - docker run dynamodb-local on Github Actions Workflow hanging github 工作流程:连接到 docker 容器时出现“ECONNREFUSED 127.0.0.1:***”错误 - github workflow: “ECONNREFUSED 127.0.0.1:***” error when connecting to docker container 如何在 github 操作中连接到 docker 容器? - How can I connect to a docker container in github actions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM