Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get prod config values from github secrets #4

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ jobs:
- name: Login to Amazon ECR
id: login-ecr # Here we specify id to be able to link to this steps output in the next step
uses: aws-actions/amazon-ecr-login@v1
# In tutorial, here is a step to retrieve config values, which are sensitvie data(secrets), from AWS secret manager
# The idea is simple, these values are safely stored on AWS and we can get them using awscli, they are in json format, so later we use jq to transform them to a format
# that can be passed to app.env to replace values stored there
# This way an image that is passed to ECR has an app.env file with values retrieved from AWS secret manager and then viper reads these values from a file as in local instance
# The same effect can be achieved by declaring secrets in GitHub secrets and then retrieving them here when actions are ran or when using k8s, these values can be passed
# in secrets file, that way they are declared as env vars and viper can read them
# - name: Load secrets and save to app.env
# run: aws secretsmanager get-secret-value --secret-id simple_bank --query SecretString --output text | jq -r 'to_entries|map("\(.key)=\(.value)")|.[]' > app.env
- name: Set prod config values
env:
DB_SOURCE: ${{ secrets.DB_SOURCE }}
TOKEN_SYMMETRIC_KEY: ${{ secrets.TOKEN_SYMMETRIC_KEY }}
run: echo "DB_DRIVER=postgres
DB_SOURCE=${DB_SOURCE}
SERVER_ADDRESS=0.0.0.0:8080
TOKEN_SYMMETRIC_KEY=${TOKEN_SYMMETRIC_KEY}
ACCESS_TOKEN_DURATION=15m" > app.env
- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
# as a prefix for the images, containers, network and as a name of the app in the docker desktop app

# When using docker in general, when postgres is created from image and POSTGRES_DB=<my_db> is specified
# the default db created inside will be named "my_db"
# the default db is created inside and it will be named "my_db"

# "-" indicates that the value is a part of a list
# if "-" is not used it means that value is key-value pair in a dictionary
Expand Down
5 changes: 4 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
set -e

echo "run db migration"
# DB_SOURCE is defined in the docker-compose.yaml and the below command will late use its value
# If Dockerfile is not run with docker-compose, DB_SOURCE env var is not defined, so we must extract env var values from the app.env
# file so that it can be used in the migrate step here
source /app/app.env
# When ran with dokcer-composee DB_SOURCE is defined in the docker-compose.yaml and the below command will later use its value
/app/migrate -path /app/migration -database "$DB_SOURCE" -verbose up

echo "start the app"
Expand Down