Skip to content

Commit

Permalink
Merge pull request #80 from allister-grange/feature/docker
Browse files Browse the repository at this point in the history
Feature/docker
  • Loading branch information
allister-grange authored Nov 5, 2024
2 parents 29a8f9f + 30750a8 commit a5796f7
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
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
2 changes: 2 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ OUTLOOK_CLIENT_ID=
OUTLOOK_CLIENT_SECRET=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
DATABASE_URL=
DATABASE_URL_UNPOOLED=
ANALYTICS_ENABLED=
53 changes: 53 additions & 0 deletions .github/workflows/pipeline.yml
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
125 changes: 125 additions & 0 deletions Dockerfile
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

View workflow job for this annotation

GitHub Actions / Build Docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "STRAVA_SECRET") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV STRAVA_SECRET=${STRAVA_SECRET}

ARG WEATHERAPI_TOKEN

Check warning on line 62 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build Docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "WEATHERAPI_TOKEN") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
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

View workflow job for this annotation

GitHub Actions / Build Docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "SPOTIFY_CLIENT_SECRET") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV SPOTIFY_CLIENT_SECRET=${SPOTIFY_CLIENT_SECRET}

ARG FINNHUB_SECRET

Check warning on line 71 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build Docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "FINNHUB_SECRET") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV FINNHUB_SECRET=${FINNHUB_SECRET}

Check warning on line 72 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build Docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "FINNHUB_SECRET") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

ARG TWITTER_CLIENT_ID
ENV TWITTER_CLIENT_ID=${TWITTER_CLIENT_ID}

ARG TWITTER_CLIENT_SECRET

Check warning on line 77 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build Docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "TWITTER_CLIENT_SECRET") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV TWITTER_CLIENT_SECRET=${TWITTER_CLIENT_SECRET}

Check warning on line 78 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build Docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "TWITTER_CLIENT_SECRET") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

ARG TWITTER_CODE_CHALLENGE_KEY
ENV TWITTER_CODE_CHALLENGE_KEY=${TWITTER_CODE_CHALLENGE_KEY}

Check warning on line 81 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build Docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "TWITTER_CODE_CHALLENGE_KEY") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

ARG TOKEN_ENCRYPT_KEY

Check warning on line 83 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build Docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "TOKEN_ENCRYPT_KEY") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
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

View workflow job for this annotation

GitHub Actions / Build Docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "GOOGLE_CLIENT_SECRET") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
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"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ OUTLOOK_CLIENT_ID=<YOUR_SECRET_HERE>
OUTLOOK_CLIENT_SECRET=<YOUR_SECRET_HERE>
GOOGLE_CLIENT_ID=<YOUR_SECRET_HERE>
GOOGLE_CLIENT_SECRET=<YOUR_SECRET_HERE>
DATABASE_URL=<YOUR_SECRET_HERE>
DATABASE_URL_UNPOOLED=<YOUR_SECRET_HERE>
ANALYTICS_ENABLED=<true or false>
```

Expand Down
Binary file removed image_tile_demo.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({

module.exports = withBundleAnalyzer({
reactStrictMode: true,
output: "standalone",
i18n: {
locales: ["en"],
defaultLocale: "en",
Expand Down
6 changes: 3 additions & 3 deletions src/components/suggestions/SuggestionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const SuggestionCard: React.FC<SuggestionCardProps> = ({
}
try {
// doesn't matter too much if their vote disappears, c'est la vie
setVotes((votes) => votes + 1);
setVotes((votes: number) => votes + 1);
const voteRes = await fetch(
`/api/suggestions/vote?suggestionId=${suggestion.id}`,
{
Expand All @@ -49,7 +49,7 @@ export const SuggestionCard: React.FC<SuggestionCardProps> = ({
throw new Error("Failed to vote");
}
} catch (err) {
setVotes((votes) => votes - 1);
setVotes((votes: number) => votes - 1);
setLiked(false);
console.error(err);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ export const SuggestionCard: React.FC<SuggestionCardProps> = ({
{suggestion.author}
</Text>
<Box>
{tags.map((tag, index) => (
{tags.map((tag: string, index: number) => (
<Badge
key={index}
colorScheme={getRandomColor()}
Expand Down
6 changes: 3 additions & 3 deletions src/components/themes/MarketplaceThemeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const MarketPlaceThemeCard: React.FC<MarketPlaceThemeCardProps> = ({
}
try {
// doesn't matter too much if their vote disappears, c'est la vie
setVotes((votes) => votes + 1);
setVotes((votes: number) => votes + 1);
const voteRes = await fetch(`/api/themes/item/vote?themeId=${theme.id}`, {
method: "POST",
});
Expand All @@ -98,7 +98,7 @@ export const MarketPlaceThemeCard: React.FC<MarketPlaceThemeCardProps> = ({
throw new Error("Failed to vote");
}
} catch (err) {
setVotes((votes) => votes - 1);
setVotes((votes: number) => votes - 1);
setLiked(false);
console.error(err);
}
Expand Down Expand Up @@ -179,7 +179,7 @@ export const MarketPlaceThemeCard: React.FC<MarketPlaceThemeCardProps> = ({
</Badge>
</Text>
<Flex mt="3">
{theme.tags.split(",").map((tag, idx) => (
{theme.tags.split(",").map((tag: string, idx: number) => (
<Badge
key={idx + tag}
filter={themeSettings.globalSettings.textColor}
Expand Down
10 changes: 0 additions & 10 deletions src/helpers/redirectHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
export const getClientUrl = (): string => {
return process.env.HOSTED_URL
? `https://${process.env.HOSTED_URL}`
: "http://localhost:3000/";
};

export const getApiUrl = (): string => {
return process.env.VERCEL_URL ? process.env.VERCEL_URL : process.env.API_URL!;
};

export const getSpotifyRedirectUrl = (): string => {
return process.env.HOSTED_URL
? `https://${process.env.HOSTED_URL}/api/spotify/auth/authorize`
Expand Down

0 comments on commit a5796f7

Please sign in to comment.