init #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: production | |
on: | |
push: | |
branches: | |
- "master" | |
env: | |
REGISTRY: us-docker.pkg.dev/xxcloud/app/app-be | |
IMAGE: prod | |
DEPLOYMENT: api | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} | |
CLUSTER_NAME: ${{ secrets.CLUSTER_NAME }} | |
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
GKE_PROJECT: ${{ secrets.GKE_PROJECT }} | |
GKE_ZONE: ${{ secrets.GKE_ZONE }} | |
GKE_SA_KEY: ${{ secrets.GKE_SA_KEY }} | |
jobs: | |
api: | |
name: deploy | |
runs-on: ubuntu-latest | |
container: catthehacker/ubuntu:act-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildxbe-cache | |
key: ${{ runner.os }}-buildxbe-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildxbe- | |
- name: Get short SHA | |
id: slug | |
run: echo "::set-output name=sha7::$(git rev-parse --short HEAD)" | |
- name: Login to GCR | |
uses: docker/login-action@v1 | |
with: | |
registry: us-docker.pkg.dev | |
username: _json_key | |
password: ${{ secrets.GKE_SA_KEY }} | |
- name: install aws cli | |
run: curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip -qq awscliv2.zip && sudo ./aws/install | |
- name: kube configure | |
run: aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name $CLUSTER_NAME | |
env: | |
AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }} | |
CLUSTER_NAME: ${{ env.CLUSTER_NAME }} | |
- name: Set up k8s | |
run: curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" | |
- name: Set chmod +x kubectl | |
run: chmod +x kubectl | |
- name: Kubernetes Cluster info | |
run: ./kubectl cluster-info | |
env: | |
AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }} | |
- name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
push: true | |
tags: ${{ env.REGISTRY }}:${{ env.IMAGE }}-${{ steps.slug.outputs.sha7 }},${{ env.REGISTRY }}:latest | |
platforms: linux/amd64 | |
cache-from: type=local,src=/tmp/.buildxbe-cache | |
cache-to: type=local,dest=/tmp/.buildxbe-cache-new,mode=max | |
build-args: | | |
GITHUB_SHA=${{ github.sha }} | |
GITHUB_REF=${{ github.ref }} | |
NPM_AUTH_TOKEN=${{ env.NPM_AUTH_TOKEN }} | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildxbe-cache | |
mv /tmp/.buildxbe-cache-new /tmp/.buildxbe-cache | |
# Deploy the Docker image to the GKE cluster | |
- name: Deploy/Update new Image to Kubernetes | |
run: ./kubectl set image deploy/$DEPLOYMENT $DEPLOYMENT=$REGISTRY:$IMAGE-${{ steps.slug.outputs.sha7 }} | |
env: | |
AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }} |