-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
Feature/docker
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Dockerfile | ||
.dockerignore | ||
node_modules | ||
npm-debug.log | ||
README.md | ||
.next | ||
.git |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Docker Build & Publish | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
build: | ||
name: Build Docker | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME}} | ||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN}} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: true | ||
platforms: linux/arm64 | ||
build-args: | | ||
STRAVA_CLIENT_ID=${{ secrets.STRAVA_CLIENT_ID }} | ||
STRAVA_SECRET=${{ secrets.STRAVA_SECRET }} | ||
WEATHERAPI_TOKEN=${{ secrets.WEATHERAPI_TOKEN }} | ||
SPOTIFY_CLIENT_ID=${{ secrets.SPOTIFY_CLIENT_ID }} | ||
SPOTIFY_CLIENT_SECRET=${{ secrets.SPOTIFY_CLIENT_SECRET }} | ||
FINNHUB_SECRET=${{ secrets.FINNHUB_SECRET }} | ||
HOSTED_URL=${{ secrets.HOSTED_URL }} | ||
TWITTER_CLIENT_ID=${{ secrets.TWITTER_CLIENT_ID }} | ||
TWITTER_CLIENT_SECRET=${{ secrets.TWITTER_CLIENT_SECRET }} | ||
TWITTER_CODE_CHALLENGE_KEY=${{ secrets.TWITTER_CODE_CHALLENGE_KEY }} | ||
TOKEN_ENCRYPT_KEY=${{ secrets.TOKEN_ENCRYPT_KEY }} | ||
OUTLOOK_CLIENT_ID=${{ secrets.OUTLOOK_CLIENT_ID }} | ||
OUTLOOK_CLIENT_SECRET=${{ secrets.OUTLOOK_CLIENT_SECRET }} | ||
GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} | ||
GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} | ||
ANALYTICS_ENABLED=${{ secrets.ANALYTICS_ENABLED }} | ||
DATABASE_URL=${{ secrets.DATABASE_URL }} | ||
DATABASE_URL_UNPOOLED=${{ secrets.DATABASE_URL_UNPOOLED }} | ||
tags: | | ||
${{ secrets.DOCKER_HUB_USERNAME}}/startertab:${{ github.sha }} | ||
${{ secrets.DOCKER_HUB_USERNAME}}/startertab:latest |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
FROM node:18-alpine AS base | ||
|
||
# Install dependencies only when needed | ||
FROM base AS deps | ||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. | ||
RUN apk add --no-cache libc6-compat | ||
WORKDIR /app | ||
|
||
# Install dependencies based on the preferred package manager | ||
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ | ||
RUN \ | ||
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ | ||
elif [ -f package-lock.json ]; then npm ci; \ | ||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ | ||
else echo "Lockfile not found." && exit 1; \ | ||
fi | ||
|
||
|
||
# Rebuild the source code only when needed | ||
FROM base AS builder | ||
WORKDIR /app | ||
COPY --from=deps /app/node_modules ./node_modules | ||
COPY . . | ||
|
||
# Next.js collects completely anonymous telemetry data about general usage. | ||
# Learn more here: https://nextjs.org/telemetry | ||
# Uncomment the following line in case you want to disable telemetry during the build. | ||
# ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
||
RUN npx prisma generate | ||
|
||
RUN \ | ||
if [ -f yarn.lock ]; then yarn run build; \ | ||
elif [ -f package-lock.json ]; then npm run build; \ | ||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \ | ||
else echo "Lockfile not found." && exit 1; \ | ||
fi | ||
|
||
# Production image, copy all the files and run next | ||
FROM base AS runner | ||
WORKDIR /app | ||
|
||
ENV NODE_ENV=production | ||
# Uncomment the following line in case you want to disable telemetry during runtime. | ||
# ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
|
||
COPY --from=builder /app/public ./public | ||
|
||
|
||
ARG HOSTED_URL | ||
ENV HOSTED_URL=${HOSTED_URL} | ||
|
||
ARG STRAVA_CLIENT_ID | ||
ENV STRAVA_CLIENT_ID=${STRAVA_CLIENT_ID} | ||
|
||
ARG STRAVA_SECRET | ||
Check warning on line 59 in Dockerfile GitHub Actions / Build DockerSensitive data should not be used in the ARG or ENV commands
|
||
ENV STRAVA_SECRET=${STRAVA_SECRET} | ||
|
||
ARG WEATHERAPI_TOKEN | ||
Check warning on line 62 in Dockerfile GitHub Actions / Build DockerSensitive data should not be used in the ARG or ENV commands
|
||
ENV WEATHERAPI_TOKEN=${WEATHERAPI_TOKEN} | ||
|
||
ARG SPOTIFY_CLIENT_ID | ||
ENV SPOTIFY_CLIENT_ID=${SPOTIFY_CLIENT_ID} | ||
|
||
ARG SPOTIFY_CLIENT_SECRET | ||
Check warning on line 68 in Dockerfile GitHub Actions / Build DockerSensitive data should not be used in the ARG or ENV commands
|
||
ENV SPOTIFY_CLIENT_SECRET=${SPOTIFY_CLIENT_SECRET} | ||
|
||
ARG FINNHUB_SECRET | ||
Check warning on line 71 in Dockerfile GitHub Actions / Build DockerSensitive data should not be used in the ARG or ENV commands
|
||
ENV FINNHUB_SECRET=${FINNHUB_SECRET} | ||
Check warning on line 72 in Dockerfile GitHub Actions / Build DockerSensitive data should not be used in the ARG or ENV commands
|
||
|
||
ARG TWITTER_CLIENT_ID | ||
ENV TWITTER_CLIENT_ID=${TWITTER_CLIENT_ID} | ||
|
||
ARG TWITTER_CLIENT_SECRET | ||
Check warning on line 77 in Dockerfile GitHub Actions / Build DockerSensitive data should not be used in the ARG or ENV commands
|
||
ENV TWITTER_CLIENT_SECRET=${TWITTER_CLIENT_SECRET} | ||
Check warning on line 78 in Dockerfile GitHub Actions / Build DockerSensitive data should not be used in the ARG or ENV commands
|
||
|
||
ARG TWITTER_CODE_CHALLENGE_KEY | ||
ENV TWITTER_CODE_CHALLENGE_KEY=${TWITTER_CODE_CHALLENGE_KEY} | ||
Check warning on line 81 in Dockerfile GitHub Actions / Build DockerSensitive data should not be used in the ARG or ENV commands
|
||
|
||
ARG TOKEN_ENCRYPT_KEY | ||
Check warning on line 83 in Dockerfile GitHub Actions / Build DockerSensitive data should not be used in the ARG or ENV commands
|
||
ENV TOKEN_ENCRYPT_KEY=${TOKEN_ENCRYPT_KEY} | ||
|
||
ARG OUTLOOK_CLIENT_ID | ||
ENV OUTLOOK_CLIENT_ID=${OUTLOOK_CLIENT_ID} | ||
|
||
ARG OUTLOOK_CLIENT_SECRET | ||
ENV OUTLOOK_CLIENT_SECRET=${OUTLOOK_CLIENT_SECRET} | ||
|
||
ARG GOOGLE_CLIENT_ID | ||
ENV GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID} | ||
|
||
ARG GOOGLE_CLIENT_SECRET | ||
Check warning on line 95 in Dockerfile GitHub Actions / Build DockerSensitive data should not be used in the ARG or ENV commands
|
||
ENV GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET} | ||
|
||
ARG DATABASE_URL | ||
ENV DATABASE_URL=${DATABASE_URL} | ||
|
||
ARG DATABASE_URL_UNPOOLED | ||
ENV DATABASE_URL_UNPOOLED=${DATABASE_URL_UNPOOLED} | ||
|
||
ARG ANALYTICS_ENABLED | ||
ENV ANALYTICS_ENABLED=${ANALYTICS_ENABLED} | ||
|
||
# Set the correct permission for prerender cache | ||
RUN mkdir .next | ||
RUN chown nextjs:nodejs .next | ||
|
||
# Automatically leverage output traces to reduce image size | ||
# https://nextjs.org/docs/advanced-features/output-file-tracing | ||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ | ||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static | ||
|
||
USER nextjs | ||
|
||
EXPOSE 3000 | ||
|
||
ENV PORT=3000 | ||
|
||
# server.js is created by next build from the standalone output | ||
# https://nextjs.org/docs/pages/api-reference/next-config-js/output | ||
ENV HOSTNAME="0.0.0.0" | ||
CMD ["node", "server.js"] |