Skip to content

Commit

Permalink
Deploy Client through ci/cd.
Browse files Browse the repository at this point in the history
  • Loading branch information
anybodys committed Feb 18, 2024
1 parent ad79bff commit 3df9000
Show file tree
Hide file tree
Showing 8 changed files with 15,705 additions and 10,294 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Client CI/CD

on:
push:
paths:
- 'client/**'
- '.github/workflows/client.yaml*'

defaults:
run:
working-directory: client

env:
GOOGLE_CREDENTIALS: ${{ secrets.GCP_CD }}
REGION: 'us-west2'
PROJECT: "artist-2d"
SERVICE_NAME: "artist-2d-client"

jobs:
build:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
- run: npm run build
env:
NODE_OPTIONS: "--openssl-legacy-provider"

deploy-gcr:
name: Deploy to GCR
#needs: build
runs-on: ubuntu-latest
#if: github.ref == 'refs/heads/main'

env:
IMAGE_TAG: "gcr.io/${PROJECT}/client:${GITHUB_SHA}"

steps:
- name: Checkout Repo
uses: actions/checkout@main
- uses: actions/checkout@v4
- name: Setup GCloud Auth
id: auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_CD }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2

# Build and push image to Google Container Registry
- name: Build & Push
run: gcloud builds submit --tag ${{ env.IMAGE_TAG }}
env:
NODE_OPTIONS: "--openssl-legacy-provider"

# Deploy image to Cloud Run
- name: Deploy GCR
run: |-
gcloud run deploy "$SERVICE_NAME" \
--quiet \
--region "$REGION" \
--image ${{ env.IMAGE_TAG }} \
--platform "managed" \
--allow-unauthenticated
3 changes: 3 additions & 0 deletions .github/workflows/infra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Terraform CD

on:
push:
paths:
- 'infra/**'
- '.github/workflows/infra.yaml'

env:
GOOGLE_CREDENTIALS: ${{ secrets.GCP_CD }}
Expand Down
6 changes: 6 additions & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
build
.dockerignore
Dockerfile
Dockerfile.prod
.gcloudignore
32 changes: 32 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# pull official base image
FROM node:20.11-slim

# Create a directory for our application in the container
RUN mkdir -p /usr/src/app

# Set this new directory as our working directory for subsequent instructions
WORKDIR /usr/src/app

# Copy all files in the current directory into the container
COPY . .

# Set the PYTHONPATH environment variable, which is occasionally necessary for certain node packages
# 'PWD' is an environment variable that stores the path of the current working directory
ENV PYTHONPATH=${PYTHONPATH}:${PWD}

# Set the environment variable for the application's port
ENV PORT 3000

# Works with newer versions of node.
ENV NODE_OPTIONS "--openssl-legacy-provider"

# Install 'serve', a static file serving package globally in the container
RUN npm install -g serve

# Install all the node modules required by the React app
RUN npm install
# Build the React app
RUN npm run build

# Serve the 'build' directory on port 3000 using 'serve'
CMD ["serve", "-s", "-l", "3000", "./build"]
Loading

0 comments on commit 3df9000

Please sign in to comment.