Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #58 from systemphil/feature/deployments
Browse files Browse the repository at this point in the history
feature deployments
  • Loading branch information
Firgrep authored May 18, 2024
2 parents c7021e7 + 02d274f commit 13b4dd2
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 6 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.env
.env.dev
.env.example
.env.master
.env.production
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ EMAIL_SEND=
EMAIL_RECEIVE=

# Analytics
NEXT_PUBLIC_SITE_ROOT=
NEXT_PUBLIC_GA_ID=
59 changes: 59 additions & 0 deletions .github/workflows/ci-cd-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Deploy Dev

on:
workflow_dispatch:
push:
branches: ["main"]

env:
# TODO turn these into repo envs
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
SERVICE: ${{ secrets.GCP_SERVICE }}
REGION: ${{ secrets.GCP_REGION }}
TAG: latest
# RUNNER_SERVICE_ACCOUNT:

jobs:
deploy:
environment: development
runs-on: ubuntu-latest
steps:
# Checkout the repo and make it accessible to workflow
- name: Checkout
uses: actions/checkout@v4

# Authenticate to Google Cloud
- name: Google Auth
id: auth
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"

# Authenticate Docker to Google Cloud Artifact Registry
- name: Docker Auth
id: docker-auth
uses: "docker/login-action@v3"
with:
username: _json_key
password: "${{ secrets.GOOGLE_CREDENTIALS }}"
registry: "${{ env.REGION }}-docker.pkg.dev"

# Build and Push Container to Google Cloud Artifact Registry
# ! Remember to add "" to secrets that contain @, &, or other special characters
- name: Build and Push Container
run: |
docker build --no-cache \
--build-arg NEXT_PUBLIC_GA_ID=${{secrets.NEXT_PUBLIC_GA_ID}} \
-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 }}"
# Deploy to Cloud Run
- name: Deploy to Cloud Run
run: |
gcloud run deploy ${{env.SERVICE}} \
--platform=managed \
--region=${{ env.REGION }} \
--image="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}" \
--min-instances=default \
--max-instances=1
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM node:20-bullseye as installer
WORKDIR /app
COPY prisma ./
COPY package*.json ./

FROM node:20-bullseye as builder
WORKDIR /app
COPY --from=installer /app/node_modules/ /app/node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED 1

ARG NEXT_PUBLIC_GA_ID
ENV NEXT_PUBLIC_GA_ID=$NEXT_PUBLIC_GA_ID

RUN npm run build

# Force node.js to use ipv4 first, over ipv6, by appending the following to server.js
RUN echo "const dns = require('node:dns');" >> ./.next/standalone/server.js \
&& echo "dns.setDefaultResultOrder('ipv4first');" >> ./.next/standalone/server.js

FROM node:20-bullseye as runner
WORKDIR /app

ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/public ./public

USER nextjs
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"

CMD [server.js]
15 changes: 10 additions & 5 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "standalone",
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'storage.googleapis.com',
port: '',
protocol: "https",
hostname: "storage.googleapis.com",
port: "",
pathname: `/${process.env.GCP_SECONDARY_BUCKET_NAME}/**`,
},
],
},
}
webpack: (config, { isServer }) => {
config.resolve.alias["@"] = path.join(__dirname, "src");
return config;
},
};

module.exports = nextConfig
module.exports = nextConfig;
Binary file modified src/app/favicon.ico
Binary file not shown.

0 comments on commit 13b4dd2

Please sign in to comment.