Skip to content

Commit 0c53c54

Browse files
author
Bryan Sieber
committed
Github actions and workflows for deployment
1 parent d5f84bc commit 0c53c54

File tree

2 files changed

+87
-35
lines changed

2 files changed

+87
-35
lines changed

.github/workflows/build-image.yaml

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
build-image:
3030
runs-on: ubuntu-latest
3131
needs: prepare
32+
environment:
33+
name: dev
3234

3335
steps:
3436
- name: Echo tag
@@ -40,39 +42,46 @@ jobs:
4042
echo $IMAGE_TAG
4143
- name: Checkout
4244
uses: actions/checkout@v2
45+
- name: Setup Gcloud Account
46+
env:
47+
IMAGE_NAME: gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_APP_NAME }}
48+
steps:
49+
- name: Login
50+
uses: google-github-actions/setup-gcloud@v0
51+
with:
52+
project_id: ${{ secrets.GCP_PROJECT_ID }}
53+
service_account_email: ${{ secrets.GCP_EMAIL }}
54+
service_account_key: ${{ secrets.GCP_CREDENTIALS }}
55+
56+
- name: Configure Docker
57+
run: gcloud auth configure-docker --quiet
58+
59+
- name: Checkout repository
60+
uses: actions/checkout@v2
61+
62+
- name: Build Docker image
63+
run: docker build . -t $IMAGE_NAME
4364

44-
# - name: Configure AWS Credentials
45-
# uses: aws-actions/configure-aws-credentials@v1
46-
# id: configure-aws-creds
47-
# env:
48-
# AWS_REGION: us-west-2
49-
# with:
50-
# aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
51-
# aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
52-
# aws-region: ${{ env.AWS_REGION }}
53-
#
54-
# - name: Login to Amazon ECR
55-
# id: login-ecr
56-
# uses: aws-actions/amazon-ecr-login@v1
57-
#
58-
# - name: Build and push to ECR
59-
# id: build-push
60-
# env:
61-
# ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
62-
# ECR_REPOSITORY: jira-bugzilla-integration
63-
# IMAGE_TAG: ${{ needs.prepare.outputs.FULL_IMAGE_TAG }}
64-
# run: |
65-
# printf '{\n "commit": "%s",\n "version": "%s",\n "image_tag": "%s",\n "source": "%s",\n "build": "%s"\n}\n' \
66-
# "$GITHUB_SHA" \
67-
# "$GITHUB_REF" \
68-
# "$IMAGE_TAG" \
69-
# "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
70-
# "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > ./version.json
71-
# docker build --file infra/Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
72-
# docker image tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
73-
# docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
74-
# docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
75-
# - name: Logut of Amazon ECR
76-
# if: always()
77-
# run: |
78-
# docker logout ${{ steps.login-ecr.outputs.registry }}
65+
- name: Test Docker image
66+
run: docker run $IMAGE_NAME sh -c "go test -v"
67+
68+
- name: Push Docker image
69+
run: docker push $IMAGE_NAME
70+
71+
- name: Build and push to GCR v2
72+
id: build-push
73+
env:
74+
GCR_REGISTRY: gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_APP_NAME }}
75+
GCR_REPOSITORY: jira-bugzilla-integration
76+
IMAGE_TAG: ${{ needs.prepare.outputs.FULL_IMAGE_TAG }}
77+
run: |
78+
printf '{\n "commit": "%s",\n "version": "%s",\n "image_tag": "%s",\n "source": "%s",\n "build": "%s"\n}\n' \
79+
"$GITHUB_SHA" \
80+
"$GITHUB_REF" \
81+
"$IMAGE_TAG" \
82+
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
83+
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > ./version.json
84+
docker build --file infra/Dockerfile -t $GCR_REGISTRY/$GCR_REPOSITORY:$IMAGE_TAG .
85+
docker image tag $GCR_REGISTRY/$GCR_REPOSITORY:$IMAGE_TAG $GCR_REGISTRY/$GCR_REPOSITORY:latest
86+
docker push $GCR_REGISTRY/$GCR_REPOSITORY:$IMAGE_TAG
87+
docker push $GCR_REGISTRY/$GCR_REPOSITORY:latest

.github/workflows/gcp-deploy.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches: [ deploy ]
6+
pull_request:
7+
branches: [ deploy ]
8+
9+
jobs:
10+
11+
deploy:
12+
environment:
13+
name: dev
14+
name: Setup Gcloud Account
15+
runs-on: ubuntu-latest
16+
env:
17+
IMAGE_NAME: gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_APP_NAME }}
18+
steps:
19+
20+
- name: Login
21+
uses: google-github-actions/setup-gcloud@v0
22+
with:
23+
project_id: ${{ secrets.GCP_PROJECT_ID }}
24+
service_account_email: ${{ secrets.GCP_EMAIL }}
25+
service_account_key: ${{ secrets.GCP_CREDENTIALS }}
26+
27+
- name: Configure Docker
28+
run: gcloud auth configure-docker --quiet
29+
30+
- name: Checkout repository
31+
uses: actions/checkout@v2
32+
33+
- name: Build Docker image
34+
run: docker build . -t $IMAGE_NAME
35+
36+
- name: Test Docker image
37+
run: docker run $IMAGE_NAME sh -c "go test -v"
38+
39+
- name: Push Docker image
40+
run: docker push $IMAGE_NAME
41+
42+
- name: Deploy Docker image
43+
run: gcloud run deploy ${{ secrets.GCP_PROJECT_ID }} --image $IMAGE_NAME --region us-central1 --platform managed

0 commit comments

Comments
 (0)