Skip to content

Commit

Permalink
deploy bot to GCR
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasForst committed Apr 30, 2020
1 parent c087d73 commit a2aca2b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- master

env:
DOCKER_IMAGE: lukaswire/polls
DOCKER_IMAGE: wire-bot/poll

jobs:
publish:
Expand All @@ -22,10 +22,13 @@ jobs:
- name: Build docker image, push
uses: docker/build-push-action@v1
with:
# login to repo
# set docker image
repository: ${{ env.DOCKER_IMAGE }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# use GCR repository
registry: eu.gcr.io
# see https://github.com/marketplace/actions/docker-build-push#google-container-registry-gcr
username: _json_key
password: ${{ secrets.GCR_ACCESS_JSON }}
# pass release_version
build_args: release_version=${{ env.RELEASE_VERSION }}
# tag the image with name of the branch - latest as this is master
Expand All @@ -45,4 +48,3 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.WEBHOOK_CI }}
# Send message only if previous step failed
if: failure()

33 changes: 19 additions & 14 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types: published

env:
DOCKER_IMAGE: lukaswire/polls
DOCKER_IMAGE: wire-bot/poll
SERVICE_NAME: poll

jobs:
Expand All @@ -22,10 +22,13 @@ jobs:
- name: Build and publish docker image
uses: docker/build-push-action@v1
with:
# login to repo
# set docker image
repository: ${{ env.DOCKER_IMAGE }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# use GCR repository
registry: eu.gcr.io
# see https://github.com/marketplace/actions/docker-build-push#google-container-registry-gcr
username: _json_key
password: ${{ secrets.GCR_ACCESS_JSON }}
# pass release_version
build_args: release_version=${{ env.RELEASE_VERSION }}
# tag the image with latest git tag
Expand All @@ -52,11 +55,11 @@ jobs:
IMAGE: ${{ env.DOCKER_IMAGE }}
SERVICE: ${{ env.SERVICE_NAME }}
VERSION: ${{ env.RELEASE_VERSION }}
run: |-
run: |
# go to directory with configuration
cd "rubicon/prod/services/$SERVICE"
# escape literals for the sed
export SED_PREPARED=$(echo $IMAGE | awk '{ gsub("/", "\\/", $1); print $1 }')
# escape literals for the sed and set output with GCR
export SED_PREPARED=$(echo $IMAGE | awk '{ gsub("/", "\\/", $1); print "eu.gcr.io\\/"$1 }')
# update final yaml
sed -i".bak" "s/image: $SED_PREPARED.*/image: $SED_PREPARED:$VERSION/g" "$SERVICE.yaml"
# delete bakup file
Expand All @@ -67,26 +70,28 @@ jobs:
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '286.0.0'
service_account_email: ${{ secrets.GKE_SA_EMAIL }}
service_account_email: [email protected]
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}
project_id: wire-bot

# Configure Docker to use the gcloud command-line tool
- name: Configure Docker Google cloud
run: |-
run: |
gcloud --quiet auth configure-docker
# Get the GKE credentials so we can deploy to the cluster
- name: Obtain k8s credentials
env:
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }}
GKE_ZONE: ${{ secrets.GKE_ZONE }}
run: |-
GKE_CLUSTER: anayotto
GKE_ZONE: europe-west1-c
run: |
gcloud container clusters get-credentials "$GKE_CLUSTER" --zone "$GKE_ZONE"
# K8s is set up, deploy the app
- name: Deploy the Service
run: |-
env:
SERVICE: ${{ env.SERVICE_NAME }}
run: |
kubectl apply -f "rubicon/prod/services/$SERVICE/$SERVICE.yaml"
# Commit all data to Rubicon and open PR
Expand Down
25 changes: 14 additions & 11 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- staging

env:
DOCKER_IMAGE: lukaswire/polls
DOCKER_IMAGE: wire-bot/poll
SERVICE_NAME: poll

jobs:
Expand All @@ -23,10 +23,13 @@ jobs:
- name: Build docker image, push
uses: docker/build-push-action@v1
with:
# login to repo
# set docker image
repository: ${{ env.DOCKER_IMAGE }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# use GCR repository
registry: eu.gcr.io
# see https://github.com/marketplace/actions/docker-build-push#google-container-registry-gcr
username: _json_key
password: ${{ secrets.GCR_ACCESS_JSON }}
# pass release_version
build_args: release_version=${{ env.RELEASE_VERSION }}
# tag the image with name of the branch - staging
Expand All @@ -41,28 +44,28 @@ jobs:
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '286.0.0'
service_account_email: ${{ secrets.GKE_SA_EMAIL }}
service_account_email: [email protected]
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}
project_id: wire-bot

# Configure Docker to use the gcloud command-line tool
- name: Configure Docker Google cloud
run: |-
run: |
gcloud --quiet auth configure-docker
# Get the GKE credentials so we can deploy to the cluster
- name: Obtain k8s credentials
env:
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }}
GKE_ZONE: ${{ secrets.GKE_ZONE }}
run: |-
GKE_CLUSTER: anayotto
GKE_ZONE: europe-west1-c
run: |
gcloud container clusters get-credentials "$GKE_CLUSTER" --zone "$GKE_ZONE"
# K8s is set up, deploy the app
- name: Deploy the Service
env:
SERVICE: ${{ env.SERVICE_NAME }}
run: |-
run: |
kubectl delete pod -l name=$SERVICE -n staging
kubectl describe pod -l name=$SERVICE -n staging
Expand Down

0 comments on commit a2aca2b

Please sign in to comment.