forked from irisnet/irishub
-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (72 loc) · 2.88 KB
/
deploy-docs.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
75
76
77
78
79
80
81
82
83
84
# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when there is a push to the "master" branch.
#
# To configure this workflow:
#
# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc.
#
# 2. Create and configure a Workload Identity Provider for GitHub (https://github.com/google-github-actions/auth#setting-up-workload-identity-federation)
#
# 3. Change the values for the GAR_LOCATION, GKE_ZONE, GKE_CLUSTER, IMAGE, REPOSITORY and DEPLOYMENT_NAME environment variables (below).
#
# For more support on how to run the workflow, please visit https://github.com/google-github-actions/setup-gcloud/tree/master/example-workflows/gke-kustomize
name: Build and Deploy Docs
on:
push:
branches: [ "master" ]
env:
GCP_WIP: ${{ secrets.GCP_WORKLOAD_IDENDITY_PROVIDER }}
GCP_SA: ${{ secrets.GCP_SERVICE_ACCOUNT }}
GKE_PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }}
GKE_REGION: ${{ secrets.GKE_REGION }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
REPOSITORY: irisnet
IMAGE: docs
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
environment: production
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout
uses: actions/checkout@v4
# Configure Workload Identity Federation and generate an access token.
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
project_id: $GKE_PROJECT_ID
workload_identity_provider: $GCP_WIP
token_format: 'access_token'
# Alternative option - authentication via credentials json
# - id: 'auth'
# uses: 'google-github-actions/auth@v0'
# with:
# credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: $DOCKER_USERNAME
password: $DOCKER_PASSWORD
# Get the GKE credentials so we can deploy to the cluster
- name: Set up GKE credentials
uses: google-github-actions/get-gke-credentials@v0
with:
cluster_name: $GKE_CLUSTER
location: $GKE_REGION
- name: Build and push docker image
uses: docker/build-push-action@v2
with:
context: ./docs
file: ./Dockerfile
push: true
tags: $REPOSITORY/$IMAGE:${{ github.sha }}
- name: Deploy to GKE
run: |
gcloud container clusters get-credentials app --region $GKE_REGION --project $GKE_PROJECT
kubectl set image -n irisnet deployment/irisnet-docs frontend=irisnet/docs:${{ github.sha }}
kubectl rollout status deployment/irisnet-docs