Parking System API developed using Golang
There are multiple environment variables that need to be setup in .env files
- Mongo DB Credentials, including:
- MONGO_URI : Connection String of form mongodb+srv://{username}:{password}@{cluster}
- MONGO_DBNAME : Database which will be used
- Google Cloud Storage
- GCS_PROJECT_ID : The Project ID of GCP being used
- GCS_BUCKET_NAME : The name of the bucket
- Environment:
- ENV: Set DEV for development environment
- GOOGLE_APPLICATION_CREDENTIALS_DEV : Used for authorization to GCS with service account key, fill in service account .json file location
- Utility:
- JWT_SECRET: Jwt secret for signing jwt
To connect to GCP, service account authentication is needed.
- Download serviceAccount.json from GCP
- Set GOOGLE_APPLICATION_CREDENTIALS_DEV as service account path locally, preferably in secrets/ folder
To upload to GCP we need to authenticate
- Installing SDK https://cloud.google.com/sdk?hl=en
- Authenticating
gcloud auth login - Set Project
gcloud config set project {PROJECT_ID}
-
Make sure modules have been installed
go mod tidy -
Build the image
docker build -t go-parking-system:$TAG .- TAG should be of form [MAJOR]:[MINOR]
- . describes the location of the Dockerfile
-
Setup Env file and serviceAccount.json as in [Running Locally]
-
Run dockerfile:
docker run --env-file .env -p 8080:8080 -v ${pwd}/secrets:/secrets go-parking-system:$TAG- --env-file to load environment variables from file (when running container, can ignore Error loading .env file error)
- -p forwards port 8080 from host to 8080 in container
- -v attaches volume from host (i.e. secrets folder) to secrets in container
-
Authenticate artifact registry
gcloud auth configure-docker asia-southeast2-docker.pkg.dev gcloud artifacts repositories describe {REGISTRY_NAME} --project={PROJECT_ID} --location=asia-southeast2 -
Tag the image
docker tag go-parking-system:$TAG asia-southeast2-docker.pkg.dev/parking-system-417615/docker/go-parking-system:$TAG -
Push to Artifact Registry
docker push asia-southeast2-docker.pkg.dev/parking-system-417615/docker/go-parking-system:$TAG