-
Notifications
You must be signed in to change notification settings - Fork 3
74 lines (65 loc) · 2.51 KB
/
deploy-gke.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Build and Deploy to GKE
on:
pull_request:
types: [opened, synchronize, reopened, edited]
branches:
- master
# Environment variables available to all jobs and steps in this workflow
env:
GKE_PROJECT: ${{ secrets.GKE_PROJECT }}
GKE_EMAIL: ${{ secrets.GKE_EMAIL }}
GITHUB_SHA: ${{ github.sha }}
GKE_ZONE: ${{ secrets.GKE_ZONE }}
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }}
IMAGE: ${{ secrets.IMAGE }}
REGISTRY_HOSTNAME: ${{ secrets.REGISTRY_HOSTNAME }}
DEPLOYMENT_NAME: ${{ secrets.DEPLOYMENT_NAME }}
SERVER: ${{ secrets.REACT_APP_SERVER }}
NAVER_MAP_KEY: ${{ secrets.REACT_APP_NAVER_MAP_KEY }}
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# set .env value
- name: set .env.* file
run: |
sed -i "1s#=#&$SERVER#" .env.production
sed -i "2s#=#&$NAVER_MAP_KEY#" .env.production
sed -i "1s#=#&$SERVER#" .env.development
sed -i "2s#=#&$NAVER_MAP_KEY#" .env.development
# Setup gcloud CLI
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '285.0.0'
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GKE_EMAIL }}
service_account_key: ${{ secrets.GKE_KEY }}
# Configure docker to use the gcloud command-line tool as a credential helper
- run: |
gcloud auth configure-docker
# Build the Docker image
- name: Build
run: |
docker build -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE":"$GITHUB_SHA" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" .
# Push the Docker image to Google Container Registry
- name: Publish
run: |
docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:$GITHUB_SHA
# Set up kustomize
- name: Set up Kustomize
run: |
curl -o kustomize --location 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: |
gcloud container clusters get-credentials $GKE_CLUSTER --zone $GKE_ZONE --project $GKE_PROJECT
./kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_SHA}
./kustomize build . | kubectl apply -f -
kubectl rollout status deployment/$DEPLOYMENT_NAME
kubectl get services -o wide