How to add github secrets to env variable
See original GitHub issueBelow is the yml file, I hope to add github secrets to env variable.
name: Publish Docker image
on:
push:
branches: [ main ]
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push to Docker Hub
uses: docker/build-push-action@v2
with:
push: true
tags: docker_hub_name/image_name:latest
secrets: |
"MYSQL_HOST=${{ secrets.MYSQL_HOST}}"
"MYSQL_USER=${{ secrets.MYSQL_USER}}"
"MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD}}"
"MYSQL_PORT=${{ secrets.MYSQL_PORT }}"
Then use syntax os.environ.get("MYSQL_HOST", "")
to get my database information when build image.
But use the below method still not work, have something syntax wrong? or other methods can do it?
secrets: |
"MYSQL_HOST=${{ secrets.MYSQL_HOST}}"
"MYSQL_USER=${{ secrets.MYSQL_USER}}"
"MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD}}"
"MYSQL_PORT=${{ secrets.MYSQL_PORT }}"
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:14 (5 by maintainers)
Top Results From Across the Web
How to use environment secret on github action? · Issue #785
Instead of putting it in your environmental variables and using the os.environ() command, you can just reference the secret directly. E.g. ...
Read more >Use Secret Environment Variables in GitHub Actions
Head to your repo in GitHub that needs the variables and click on the Settings tab. Inside of Settings, go down the sidebar...
Read more >How to use environment variables and secrets using GitHub ...
To store these files go to your GitHub project and go to Settings and then Secrets . Secrets tab. Inside this menu click...
Read more >Launching GitHub Actions Environment Variables and Secrets
Setting for GitHub Actions Environment Variables · 1. Create a directory named . · 2. Next, create a file with your preferred name...
Read more >Github Actions Environment Variables: Guide, Examples & Tips
Github Actions environment variables allow you to store information―API keys, login credentials, app secrets, constants, etc―to use in your ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This worked for me. Thanks, I documented everything here https://andrei-calazans.com/posts/2021-06-23/passing-secrets-github-actions-docker
@machineCYC
Yes
https://docs.docker.com/engine/reference/commandline/secret_create/#create-a-secret
You can also provide secrets through env vars. So let’s say you already have the env var
MYSQL_HOST
set locally, you can then set secret in buildx command:--secret id=mysql_host,env=MYSQL_HOST
and use it like this in your Dockerfile: