Build and Deploy Frontend to GCP (PROD) #3
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: Build and Deploy Frontend to GCP (PROD) | |
on: | |
workflow_dispatch: | |
env: | |
GCE_HOST: ${{ secrets.GCE_HOST_PROD }} | |
INSTANCE_NAME: 'community-search-prod-1' | |
jobs: | |
deploy-frontend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Build website | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18.17.1' | |
- run: bash frontend/build/install.sh | |
- run: bash frontend/build/build.sh | |
- name: Build and Push Docker image | |
id: build | |
env: | |
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }} | |
DOCKER_IMG: ghcr.io/jasonlo/community-search-frontend | |
run: | | |
echo $GHCR_TOKEN | docker login ghcr.io -u USERNAME --password-stdin && | |
cd frontend-built && | |
tag=$(date +%Y%m%d-%H%M) && | |
docker build . -t $DOCKER_IMG:$tag && | |
docker push $DOCKER_IMG:$tag && | |
docker tag $DOCKER_IMG:$tag $DOCKER_IMG:latest && | |
docker push $DOCKER_IMG:latest | |
- name: Deploy to GCP | |
if: steps.build.outputs.exit_code == 0 | |
env: | |
ZONE: 'us-central1-a' | |
GCE_USERNAME: 'ci' | |
GCE_SSH_KEY: ${{ secrets.GCE_SSH_KEY }} | |
run: | | |
echo "$GCE_SSH_KEY" > gce_ssh_key.pem | |
chmod 600 gce_ssh_key.pem | |
ssh -i gce_ssh_key.pem -o StrictHostKeyChecking=no $GCE_USERNAME@$GCE_HOST 'bash -s' < ./scripts/deploy_frontend.sh | |