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