In my personal project, I try to deploy my backend spring boot with github actions and a Dockerfile
For more security, I save my properties in the Github secrets and in my Dockerfile, i get the configuration (url, username and password)
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
push: true
file: ./Dockerfile
tags: ${{ env.REGISTRY }}/***
build-args: |
server_port=${{ secrets.SERVER_PORT_DEV }}
url=${{ secrets.URL_DEV }}
username=${{ secrets.USERNAME_DEV }}
password=${{ secrets.PASSWORD_DEV }}
And my spring boot doesn’t run because the url, username and password are missing in my application.properties.
So, I try to cat the properties file in my github actions and here is what i got :
#11 0.281 # Secrets
#11 0.281 spring.datasource.url=
#11 0.281 spring.datasource.username=
#11 0.281 spring.datasource.password=
Do you have any idea why Github secrets are not read?
2nd more general question: is it good practice to use this method? Or are there better ones?
Thank you very much for your precious help and good day to all of you who would help me ๐
2
Answers
Yes, in my Dockerfile I have this informations :
I don't understand why my secrets doesn't in my file, i'm so confuse
The "Set build-time variables (
--build-arg
)"docker build
man page section includes:So make sure your Dockerfile includes:
Actually, inside the Dockerfile, the GitHub Action secrets, like
${{ secrets.URL_DEV }}
would not apply.Only
${url}
, meaning theARG
name, would be available.So if you input text into
application.properties
in the Dockerfile, use theARG
variable names, not the GitHub Action secrets name.But when you call
docker build
(*outside the Dockerfile, since docker build uses the Dockerfile), then yes, use the GitHub Action secrets: