Skip to content

Commit

Permalink
feat: setup Cloud Build deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Otieno Calvine <nyarangaotieno@gmail.com>
  • Loading branch information
NYARAS committed Jul 30, 2021
1 parent 4826f5e commit 598a23a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ env:
DOCKER_BUILDKIT: 1 # Enable Buildkit and let compose use it to speed up image building
COMPOSE_DOCKER_CLI_BUILD: 1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
GOOGLE_CLOUD_PROJECT: ${{ secrets.GOOGLE_CLOUD_PROJECT }}
FIREBASE_WEB_API_KEY: ${{ secrets.FIREBASE_WEB_API_KEY }}
ENVIRONMENT: ${{ secrets.ENVIRONMENT }}
Expand All @@ -28,7 +27,6 @@ jobs:
timeout-minutes: 80
steps:
- uses: actions/checkout@v2
- run: git config --global url."https://${user}:${ACCESS_TOKEN}@gitlab.slade360emr.com".insteadOf "https://gitlab.slade360emr.com"
- uses: google-github-actions/setup-gcloud@master
with:
project_id: ${{ secrets.GOOGLE_CLOUD_PROJECT }}
Expand Down
4 changes: 0 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ CMD go mod download
# Now copy the rest.
COPY . /app/

# Set up the credentials needed to fetch private code
ARG CI_JOB_TOKEN
RUN git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.slade360emr.com".insteadOf "https://gitlab.slade360emr.com"

# Retrieve application dependencies.
RUN go mod download

Expand Down
46 changes: 46 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
steps:
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'eu.gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$COMMIT_SHA', '.']

# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'eu.gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$COMMIT_SHA']

# Deploy an image from Container Registry to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
args: [
'beta',
'run',
'deploy',
"${_SERVICE_NAME}",
'--image', 'eu.gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$COMMIT_SHA',
'--region', 'europe-west1',
'--platform', 'managed',
'--allow-unauthenticated',
'--min-instances', '1',
'--max-instances', '4',
'--memory', '1Gi',
'--cpu', '1',
'--set-secrets', '/tmp/secrets/.env=${_SECRET_NAME}:latest',
'--timeout', '59m59s'
]

# Automatically update the traffic to the latest revision
# This will update the latest revision to serve 100% traffic
- name: 'gcr.io/cloud-builders/gcloud'
args: [
'run',
'update-traffic',
"${_SERVICE_NAME}",
'--to-latest',
'--region', 'europe-west1',
'--platform', 'managed',
'--allow-unauthenticated',
]

images:
- 'eu.gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$COMMIT_SHA'

timeout: 1200s
queueTtl: 3600s

0 comments on commit 598a23a

Please sign in to comment.