Skip to content

Commit

Permalink
Feature/gke deploy (#3)
Browse files Browse the repository at this point in the history
* gke deployment added

* variable update

* kustomize build fixed

* deploy step fixed

* deploy step kustomize update

* deployment.yaml updated
  • Loading branch information
ferhatbostanci authored May 30, 2021
1 parent 1f406af commit 2c88977
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.git

.github
.kubernetes
74 changes: 74 additions & 0 deletions .github/workflows/gke-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build and Deploy to GKE

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GKE_CLUSTER: pulsey-cluster-1
GKE_ZONE: europe-west3-a
DEPLOYMENT_NAME: game-server
IMAGE: game-server

jobs:
build-and-deploy:
name: Build and Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v2

# Get git tags
- name: Get Version
id: vars
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})

# Setup gcloud CLI
- uses: google-github-actions/[email protected]
with:
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}

# Configure Docker to use the gcloud command-line tool as a credential
# helper for authentication
- run: |-
gcloud --quiet auth configure-docker
# Get the GKE credentials so we can deploy to the cluster
- uses: google-github-actions/[email protected]
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
credentials: ${{ secrets.GKE_SA_KEY }}

# Build the Docker image
- name: Build
run: |-
docker build \
--tag "gcr.io/$PROJECT_ID/$IMAGE:${{ steps.vars.outputs.tag }}" \
.
# Push the Docker image to Google Container Registry
- name: Publish
run: |-
docker push "gcr.io/$PROJECT_ID/$IMAGE:${{ steps.vars.outputs.tag }}"
# Set up kustomize
- name: Set up Kustomize
run: |-
curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
chmod u+x ./kustomize
# Deploy the Docker image to the GKE cluster
- name: Deploy
run: |-
cd .kubernetes
../kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:${{ steps.vars.outputs.tag }}
../kustomize build . | kubectl apply -f -
kubectl rollout status deployment/$DEPLOYMENT_NAME
kubectl get services -o wide
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: game-server
labels:
app: game-server
spec:
replicas: 1
selector:
Expand All @@ -16,8 +14,8 @@ spec:
spec:
containers:
- name: game-server-app
image: pulsey-game-server:latest
imagePullPolicy: Never
image: gcr.io/PROJECT_ID/IMAGE:TAG
imagePullPolicy: Always
ports:
- containerPort: 3000
readinessProbe:
Expand All @@ -30,18 +28,3 @@ spec:
port: 3000
initialDelaySeconds: 15
periodSeconds: 60

---

apiVersion: v1
kind: Service
metadata:
name: backend-grpc-service
spec:
type: LoadBalancer
selector:
app: game-server
ports:
- protocol: TCP
port: 3000
targetPort: 3000
5 changes: 5 additions & 0 deletions .kubernetes/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yaml
12 changes: 12 additions & 0 deletions .kubernetes/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: game-server-service
spec:
type: LoadBalancer
ports:
- protocol: TCP
port: 3000
targetPort: 3000
selector:
app: game-server

0 comments on commit 2c88977

Please sign in to comment.