Closed raza2022 closed 1 year ago
@Moeriki @davidmat @jesstelford @nabeards any suggestion/guidance about this use case?
Hello @raza2022
I don't know if I understood your issue right, but I just did something similar and it was a pain because I suck at that kind of stuff.
First, you need to understand this : https://vsupalov.com/docker-arg-env-variable-guide
Based on that, you know you will need an ENV with the secret to go into your container. This ENV will come from your ARG in the Dockerfile.
So, to do it, just pass along the secret in the github action workflow file you are using. For instance :
- name: Build the thing
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
push: true
build-args: |
SUPER_SECRET_THAT_HAS_BEEN_SET=${{ secrets.SUPER_SECRET_THAT_HAS_BEEN_SET }}
In the Dockerfile, you will now have an ARG that is called SUPER_SECRET_THAT_HAS_BEEN_SET. Just create an ENV out of it.
ARG SUPER_SECRET_THAT_HAS_BEEN_SET
ENV SUPER_SECRET_THAT_HAS_BEEN_SET ${SUPER_SECRET_THAT_HAS_BEEN_SET:-null}
now, your should be able to access it through process.env.SUPER_SECRET_THAT_HAS_BEEN_SET.
mongodb+srv://${process.env.SUPER_SECRET_THAT_HAS_BEEN_SET}:${process.env.SUPER_SECRET_THAT_HAS_BEEN_SET}
Closing this, as this is not a migrate-mongo issue.
I don't know am I using it right but I have a use case where I need to load GitHub secrets with dotenv file so here is my use case I am using migrate-mongo in next js which is working fine locally within nestJS application however as I am using migration within isolated JS file, so I have to load env variables separately too, like
mongodb+srv://${secrets.DATABASE_USER}:${process.env.DATABASE_PASSWORD}
so locally I just added the required dotenv module with local file path on top of migrate-mongo config file and it's working finerequire('dotenv').config({ path: '.env.development.local' })
however I couldn't able to find a solution for github action pipelines as I know in .yml file secrets can be accessed as
{{ secrets.DATABASE_USER }}
so I tried these ways in migrate-mongo configrequire('dotenv').config()
require('dotenv').config({ path: 'secrets' })
but nothing works, so my question what is the best way to achieve it on GitHub actions (with or without dotenv) any solution/guidence will be greatly appreciated