This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from systemphil/feature/deployments
feature deployments
- Loading branch information
Showing
6 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
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
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,5 +39,4 @@ EMAIL_SEND= | |
EMAIL_RECEIVE= | ||
|
||
# Analytics | ||
NEXT_PUBLIC_SITE_ROOT= | ||
NEXT_PUBLIC_GA_ID= |
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
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 |
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
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] |
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
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 not shown.