Skip to content

Commit

Permalink
feat: cloud run workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Firgrep committed Feb 1, 2024
1 parent 7200c68 commit eea8901
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 21 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.env
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git
52 changes: 31 additions & 21 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ on:
branches:
- dev

env:
PROJECT_ID: ${{ secrets.PROJECT_ID }}
SERVICE: ${{ secrets.SERVICE }}
REGION: ${{ secrets.REGION }}
TAG: latest

jobs:
build_and_deploy:
if: github.repository_owner == 'systemphil'
environment: dev
environment: dev
runs-on: ubuntu-latest

steps:
Expand All @@ -25,29 +31,33 @@ jobs:
with:
fetch-depth: 0

- name: Set Up Node.js
uses: actions/setup-node@v3
with:
node-version: 20

- name: 'Create env file'
run: |
echo "${{ secrets.ENV_FILE }}" > .env
- name: Install Dependencies
run: npm ci

- name: Build
run: npm run build

- name: Copy app.yaml to out directory
run: cp app.yaml ./out/

- name: Auth
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'

- name: Deploy
- name: Docker Auth
id: docker-auth
uses: "docker/login-action@v1"
with:
username: _json_key
password: "${{ secrets.GOOGLE_CREDENTIALS }}"
registry: "${{ env.REGION }}-docker.pkg.dev"

- name: Build and Push Container
run: |-
docker build \
-f Dockerfile \
-t "${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}" ./
docker push "${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}"
- name: Deploy to Cloud Run
run: |
gcloud app deploy app.yaml
gcloud run deploy ${{env.SERVICE}} \
--platform=managed \
--region=${{ env.REGION }} \
--allow-unauthenticated \
--max-instances=4 \
--min-instances=1 \
--update-secrets=NEXT_PUBLIC_SITE_ROOT=NEXT_PUBLIC_SITE_ROOT:latest,NEXT_PUBLIC_GA_ID=NEXT_PUBLIC_GA_ID:latest \
--image="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}"
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:20-alpine AS installer
WORKDIR /app
COPY package*.json ./
RUN npm ci

FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=installer /app/node_modules/ /app/node_modules
COPY . .
RUN npm run build

FROM node:20-alpine AS runner
WORKDIR /app
COPY --from=builder /app/build/ /app
RUN npm install -g serve
CMD ["serve", "-L"]
150 changes: 150 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@napi-rs/simple-git-linux-x64-gnu": "^0.1.9",
"@napi-rs/simple-git-linux-x64-musl": "^0.1.16",
"@types/node": "20.6.0",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
Expand Down
1 change: 1 addition & 0 deletions src/components/Analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function removeGoogleAnalytics() {

const Analytics = () => {
const GA_ID = process.env.NEXT_PUBLIC_GA_ID;
console.log(GA_ID) // TODO remove
const [hasConsentValue, setHasConsentValue] = useState<boolean>(false);

const loadGoogleAnalytics = useCallback(() => {
Expand Down
2 changes: 2 additions & 0 deletions theme.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { type DocsThemeConfig, useConfig } from "nextra-theme-docs";

const SITE_ROOT = process.env.NEXT_PUBLIC_SITE_ROOT;

console.log(SITE_ROOT); // TODO remove

const config: DocsThemeConfig = {
docsRepositoryBase: "https://github.com/systemphil/sphil/tree/main", // root for every edit link
editLink: {
Expand Down

0 comments on commit eea8901

Please sign in to comment.