Skip to content

Commit 5a2bd3b

Browse files
authored
Merge pull request #10 from drivecore/feature/issue-2-docker-cloud-run
Add Docker Container and GitHub Workflow for Cloud Run Deployment
2 parents a5a6ff1 + f43b933 commit 5a2bd3b

File tree

11 files changed

+1653
-92
lines changed

11 files changed

+1653
-92
lines changed

.dockerignore

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Dependencies
2+
node_modules
3+
.pnp
4+
.pnp.js
5+
6+
# Build outputs
7+
build
8+
.docusaurus
9+
dist
10+
coverage
11+
12+
# Git and GitHub
13+
.git
14+
.github
15+
16+
# Misc
17+
.DS_Store
18+
.env.local
19+
.env.development.local
20+
.env.test.local
21+
.env.production.local
22+
23+
# Logs
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
pnpm-debug.log*
28+
29+
# Docker
30+
Dockerfile
31+
.dockerignore
32+
33+
# Editor directories and files
34+
.idea
35+
.vscode
36+
*.suo
37+
*.ntvs*
38+
*.njsproj
39+
*.sln
40+
*.sw?

.eslintrc.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = {
2+
root: true,
3+
extends: [
4+
'eslint:recommended',
5+
'plugin:@typescript-eslint/recommended',
6+
'plugin:react/recommended',
7+
],
8+
parser: '@typescript-eslint/parser',
9+
plugins: ['@typescript-eslint', 'react'],
10+
parserOptions: {
11+
ecmaVersion: 2021,
12+
sourceType: 'module',
13+
ecmaFeatures: {
14+
jsx: true,
15+
},
16+
},
17+
settings: {
18+
react: {
19+
version: 'detect',
20+
},
21+
},
22+
env: {
23+
browser: true,
24+
node: true,
25+
es6: true,
26+
},
27+
rules: {
28+
'react/react-in-jsx-scope': 'off',
29+
'react/prop-types': 'off',
30+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
31+
},
32+
ignorePatterns: [
33+
'node_modules/',
34+
'build/',
35+
'.docusaurus/',
36+
'dist/',
37+
'**/*.d.ts',
38+
],
39+
};

.github/workflows/deploy-docs.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Deploy Documentation to Cloud Run
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
env:
10+
REGION: us-central1
11+
REGISTRY: us-central1-docker.pkg.dev
12+
PROJECT_ID: drivecore-primary
13+
SERVICE_NAME: mycoder-docs
14+
15+
jobs:
16+
deploy:
17+
name: Deploy to Cloud Run
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
id-token: write
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Google Auth
28+
id: auth
29+
uses: google-github-actions/auth@v2
30+
with:
31+
workload_identity_provider: ${{ secrets.WIF_PROVIDER }}
32+
service_account: ${{ secrets.WIF_SERVICE_ACCOUNT }}
33+
34+
- name: Set up Cloud SDK
35+
uses: google-github-actions/setup-gcloud@v2
36+
37+
- name: Configure Docker for GCP
38+
run: |
39+
gcloud auth configure-docker $REGISTRY --quiet
40+
41+
- name: Build and push Docker container
42+
run: |
43+
docker build -t $REGISTRY/$PROJECT_ID/cloud-run-deployments/$SERVICE_NAME:${{ github.sha }} .
44+
docker push $REGISTRY/$PROJECT_ID/cloud-run-deployments/$SERVICE_NAME:${{ github.sha }}
45+
46+
- name: Deploy to Cloud Run
47+
id: deploy
48+
uses: google-github-actions/deploy-cloudrun@v2
49+
with:
50+
service: ${{ env.SERVICE_NAME }}
51+
region: ${{ env.REGION }}
52+
image: ${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/cloud-run-deployments/${{ env.SERVICE_NAME }}:${{ github.sha }}
53+
flags: '--allow-unauthenticated'
54+
55+
- name: Show Output
56+
run: echo ${{ steps.deploy.outputs.url }}

.github/workflows/lint.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: ["*"]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
PNPM_VERSION: 10.2.1
11+
12+
jobs:
13+
lint:
14+
name: Lint
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup pnpm
22+
uses: pnpm/action-setup@v3
23+
with:
24+
version: ${{ env.PNPM_VERSION }}
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
cache: 'pnpm'
31+
32+
- name: Install dependencies
33+
run: pnpm install --frozen-lockfile
34+
35+
- name: Lint
36+
run: pnpm lint

Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM node:20-alpine
2+
3+
WORKDIR /app
4+
5+
# Install pnpm
6+
RUN npm install -g pnpm
7+
8+
# Copy package.json and lock files
9+
COPY package.json pnpm-lock.yaml ./
10+
11+
# Install dependencies
12+
RUN pnpm install --frozen-lockfile
13+
14+
# Copy the rest of the application
15+
COPY . .
16+
17+
# Build the Docusaurus site
18+
ENV NODE_ENV=production
19+
RUN pnpm build
20+
21+
# Expose the port the app will run on
22+
ENV PORT=8080
23+
EXPOSE ${PORT}
24+
25+
# Command to run the application
26+
CMD ["pnpm", "serve", "--port", "8080", "--no-open"]

docs/deployment.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
sidebar_position: 99
3+
title: Deployment
4+
---
5+
6+
# Deployment Process
7+
8+
This documentation site is automatically deployed to Google Cloud Run whenever changes are pushed to the main branch. This document outlines the deployment process and how to make changes to it.
9+
10+
## Automated Deployment
11+
12+
The documentation site uses GitHub Actions for continuous integration and deployment (CI/CD):
13+
14+
1. When changes are pushed to the `main` branch, a GitHub workflow is triggered
15+
2. The workflow builds the Docusaurus site and packages it in a Docker container
16+
3. The container is pushed to Google Container Registry
17+
4. The container is deployed to Google Cloud Run
18+
5. The site is accessible at the Cloud Run URL (with custom domain mapping)
19+
20+
## Deployment Infrastructure
21+
22+
The deployment infrastructure consists of:
23+
24+
- **Docker Container**: The site is packaged in a Docker container for consistent deployment
25+
- **Google Container Registry**: Stores the Docker images
26+
- **Google Cloud Run**: Hosts the documentation site
27+
- **GitHub Actions**: Automates the build and deployment process
28+
29+
## Local Development and Testing
30+
31+
To test the deployment locally:
32+
33+
1. Build the Docker image:
34+
```bash
35+
docker build -t mycoder-docs .
36+
```
37+
38+
2. Run the container locally:
39+
```bash
40+
docker run -p 8080:8080 mycoder-docs
41+
```
42+
43+
3. Access the site at http://localhost:8080
44+
45+
## Manual Deployment
46+
47+
While the deployment is automated, you can also trigger a manual deployment:
48+
49+
1. Go to the GitHub repository
50+
2. Navigate to Actions → Deploy Documentation to Cloud Run workflow
51+
3. Click "Run workflow" and select the branch to deploy
52+
53+
## Troubleshooting
54+
55+
If you encounter issues with the deployment:
56+
57+
1. Check the GitHub Actions logs for any errors
58+
2. Verify that the Docker container builds successfully locally
59+
3. Ensure the Google Cloud service account has the necessary permissions
60+
4. Check the Cloud Run logs for runtime errors
61+
62+
## Modifying the Deployment Process
63+
64+
To modify the deployment process:
65+
66+
1. Update the `.github/workflows/deploy-docs.yml` file for changes to the CI/CD pipeline
67+
2. Update the `Dockerfile` for changes to the container configuration
68+
3. Test changes locally before pushing to the repository

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"serve": "docusaurus serve",
1313
"write-translations": "docusaurus write-translations",
1414
"write-heading-ids": "docusaurus write-heading-ids",
15-
"typecheck": "tsc"
15+
"typecheck": "tsc",
16+
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
1617
},
1718
"dependencies": {
1819
"@docusaurus/core": "3.7.0",
@@ -27,6 +28,10 @@
2728
"@docusaurus/module-type-aliases": "3.7.0",
2829
"@docusaurus/tsconfig": "3.7.0",
2930
"@docusaurus/types": "3.7.0",
31+
"@typescript-eslint/eslint-plugin": "^7.0.0",
32+
"@typescript-eslint/parser": "^7.0.0",
33+
"eslint": "^8.56.0",
34+
"eslint-plugin-react": "^7.33.2",
3035
"typescript": "~5.6.2"
3136
},
3237
"browserslist": {

0 commit comments

Comments
 (0)