You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Go project that has a Dockerfile and config.yml for GitHub automation.
Simple AWS setup where I build to ECR and deploy to my EC2 instance via Elasticbeanstalk
All my AWS credentials are stored in Github Secrets.
Previously the rest of the required env variables were stored in config.env in the Go project.
All the above automation works just fine.
For better security, easier modification with branches, etc I want to move all the information out of the config.env file into the Secrets and Variables of the GitHub Action.
Unfortunately, these are not parsing through to the env variables of the Docker container as expected. I tried for a few hours last night and have got to a point where I am stumped and its just not making sense.
So this is not the complete set of variables, but it is enough to show where I am stumped.
First Step - .elasticbeanstalk\deploy.yml for GitHub
For testing purposes I have set one env manually and one from GitHub variables (I get the same result with secrets.xxx too).
${{ secrets.AWS_REGION }} etc work as expected
Both the echo's in the run block show up in the GitHub Action logs just fine as expected. So it tells me I am pulling the Variables/Secrets just fine at this point. Both --build-arg seem to work as expected too as you will see in the next part.
Second Step - Dockerfile for building the container Once again I set one of the ARG and one of the ENV manually to test.
All three echos also show up correctly in the GitHub Action logs telling me that the ARG of DB_USER is being passed in correctly at this point.
FROM golang:1.19.1
WORKDIR /app
COPY go.mod go.sum ./
# Set arguments for the build
ARG DB_USER
ARG DB_NAME
ARG DB_PORT=5454
# Set the environment variable
ENV DB_HOST=mydb.hostname.ap-southeast-2.rds.amazonaws.com
ENV DB_PORT=$DB_PORT
ENV DB_NAME=$DB_NAME
ENV DB_USER=$DB_USER
RUN echo "DB_HOST from dockerfile: $DB_HOST"
RUN echo "DB_PORT from dockerfile: $DB_PORT"
RUN echo "DB_USER from dockerfile: $DB_USER"
RUN echo "DB_NAME from dockerfile: $DB_NAME"
RUN go mod download
COPY . .
RUN go build -o main .
EXPOSE 8080
CMD ["./main"]
Last Step - Inside the Docker container BUT when I check the env variables of my Docker container the manual persists, but not the one that has been passed in from the start (DB_HOST).
All of them come through fine except DB_USER. Defined right from the start and appears in all the echos but not in the last part when I check the env variable within GoAt this point, I am stumped and have yet to find anything online that helps.
ActionsBuild, test, and automate your deployment pipeline with world-class CI/CDQuestion
1 participant
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
My deployment stack looks like this:
Go project that has a Dockerfile and config.yml for GitHub automation.
Simple AWS setup where I build to ECR and deploy to my EC2 instance via Elasticbeanstalk
All my AWS credentials are stored in Github Secrets.
Previously the rest of the required env variables were stored in config.env in the Go project.
All the above automation works just fine.
For better security, easier modification with branches, etc I want to move all the information out of the config.env file into the Secrets and Variables of the GitHub Action.
Unfortunately, these are not parsing through to the env variables of the Docker container as expected. I tried for a few hours last night and have got to a point where I am stumped and its just not making sense.
So this is not the complete set of variables, but it is enough to show where I am stumped.
First Step - .elasticbeanstalk\deploy.yml for GitHub
For testing purposes I have set one env manually and one from GitHub variables (I get the same result with secrets.xxx too).
${{ secrets.AWS_REGION }} etc work as expected
Both the echo's in the run block show up in the GitHub Action logs just fine as expected. So it tells me I am pulling the Variables/Secrets just fine at this point. Both --build-arg seem to work as expected too as you will see in the next part.
Second Step - Dockerfile for building the container Once again I set one of the ARG and one of the ENV manually to test.
All three echos also show up correctly in the GitHub Action logs telling me that the ARG of DB_USER is being passed in correctly at this point.
Last Step - Inside the Docker container BUT when I check the env variables of my Docker container the manual persists, but not the one that has been passed in from the start (DB_HOST).
All of them come through fine except DB_USER. Defined right from the start and appears in all the echos but not in the last part when I check the env variable within GoAt this point, I am stumped and have yet to find anything online that helps.
Any help would be much appreciated :)
Beta Was this translation helpful? Give feedback.
All reactions