Hi all,
My .gitlab-ci.yml deploy stage like :
deploy:
stage: deploy
before_script:
- chmod 400 $SSH_KEY
script:
- ssh to deploy server "
docker login ... && do something to pull source code including docker-compose.yml , .env
docker-compose down &&
docker-compose up -d"
There is a .env file :
DB_PASSWORD="***********"
I don’t want to store DB password in .env file, instead, I want to create a Gitlab ci/cd variables to store DB password and transmission it to container or host when deploy.
How can I do that ? Please give me some advice, thank you very much.
Hi @jack.chuong
I suppose the easiest is to generate the .env
file and put it to deploy server
- echo "DB_PASSWORD=$DB_PASSWORD" > env && scp env deploy_server:/path/.env
or generate the file on the deploy server.
Another option is to use variables in docker-compose.yml
web:
environment:
- DB_PASSWORD=${DB_PASSWORD}"
and populate the environment variable on deploy server
- ssh to deploy server "
...
DB_PASSWORD=${DB_PASSWORD} docker-compose up -d
1 Like
Hi @balonik
Thank you for your suggestion, here what I did and it works:
deploy:
stage: deploy
before_script:
- chmod 400 $SSH_KEY
script:
- ssh to deploy server "
docker login ... && do something to pull source code including docker-compose.yml , .env &&
echo "DB_PASSWORD=$DB_PASSWORD" >> .env && docker-compose down &&
docker-compose up -d && echo "" > .env"
.env is a blank file , thank you very much.