Skip to content

Commit

Permalink
fix(docker): remove unneeded build variables
Browse files Browse the repository at this point in the history
  • Loading branch information
devrsi0n committed Oct 1, 2022
1 parent e82e50e commit f62f760
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 74 deletions.
30 changes: 13 additions & 17 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Extract meta
id: builder-meta
uses: docker/metadata-action@v4
Expand All @@ -41,20 +47,10 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.builder-meta.outputs.tags }}
labels: ${{ steps.builder-meta.outputs.labels }}
build-args:
NEXT_PUBLIC_HASURA_HTTP_ORIGIN: ${{ secrets.NEXT_PUBLIC_HASURA_HTTP_ORIGIN }}
NEXT_PUBLIC_HASURA_WS_ORIGIN: ${{ secrets.NEXT_PUBLIC_HASURA_HTTP_ORIGIN }}
NEXT_PUBLIC_APP_URL: ${{ secrets.NEXT_PUBLIC_APP_URL }}
NEXT_PUBLIC_VAPID: ${{ secrets.NEXT_PUBLIC_VAPID }}
NEXT_PUBLIC_ANALYTICS_DOMAIN: ${{ secrets.NEXT_PUBLIC_ANALYTICS_DOMAIN }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}
HASURA_ADMIN_SECRET: ${{ secrets.HASURA_ADMIN_SECRET }}
HASURA_EVENT_SECRET: ${{ secrets.HASURA_EVENT_SECRET }}
HASH_ALGORITHM: ${{ secrets.HASH_ALGORITHM }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
PRIVATE_VAPID: ${{ secrets.PRIVATE_VAPID }}
EMAIL_API_KEY: ${{ secrets.EMAIL_API_KEY }}
GITHUB_CLIENT_ID: ${{ secrets.GITHUB_CLIENT_ID }}
GITHUB_CLIENT_SECRET: ${{ secrets.GITHUB_CLIENT_SECRET }}
TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }}
TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }}
cache-from: type=registry,ref=devrsi0n/chirpy:buildcache
cache-to: type=registry,ref=devrsi0n/chirpy:buildcache,mode=max
# Don't put any sensitive key to build-args, as they'll be exposed to build history
build-args: |
NEXT_PUBLIC_APP_URL=${{ secrets.NEXT_PUBLIC_APP_URL }}
NEXT_PUBLIC_ANALYTICS_DOMAIN=${{ secrets.NEXT_PUBLIC_ANALYTICS_DOMAIN }}
NEXTAUTH_URL=${{ secrets.NEXTAUTH_URL }}
30 changes: 4 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
# syntax=docker/dockerfile:1

FROM node:16-slim AS base
WORKDIR /app
ARG NEXT_PUBLIC_HASURA_HTTP_ORIGIN
ENV NEXT_PUBLIC_HASURA_HTTP_ORIGIN=${NEXT_PUBLIC_HASURA_HTTP_ORIGIN}
ARG NEXT_PUBLIC_HASURA_WS_ORIGIN
ENV NEXT_PUBLIC_HASURA_WS_ORIGIN=${NEXT_PUBLIC_HASURA_WS_ORIGIN}
ARG NEXT_PUBLIC_APP_URL
ENV NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
ARG NEXT_PUBLIC_VAPID
ENV NEXT_PUBLIC_VAPID=${NEXT_PUBLIC_VAPID}
ARG NEXT_PUBLIC_ANALYTICS_DOMAIN
ENV NEXT_PUBLIC_ANALYTICS_DOMAIN=${NEXT_PUBLIC_ANALYTICS_DOMAIN}
ARG NEXTAUTH_URL
ENV NEXTAUTH_URL=${NEXTAUTH_URL}
ARG HASURA_ADMIN_SECRET
ENV HASURA_ADMIN_SECRET=${HASURA_ADMIN_SECRET}
ARG HASURA_EVENT_SECRET
ENV HASURA_EVENT_SECRET=${HASURA_EVENT_SECRET}
ARG HASH_ALGORITHM
ENV HASH_ALGORITHM=${HASH_ALGORITHM}
ARG NEXTAUTH_SECRET
ENV NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
ARG PRIVATE_VAPID
ENV PRIVATE_VAPID=${PRIVATE_VAPID}
ARG EMAIL_API_KEY
ENV EMAIL_API_KEY=${EMAIL_API_KEY}
ARG GITHUB_CLIENT_ID
ENV GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}
ARG GITHUB_CLIENT_SECRET
ENV GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}
ARG TWITTER_CONSUMER_KEY
ENV TWITTER_CONSUMER_KEY=${TWITTER_CONSUMER_KEY}
ARG NEXT_PUBLIC_ANALYTICS_DOMAIN
ENV NEXT_PUBLIC_ANALYTICS_DOMAIN=${NEXT_PUBLIC_ANALYTICS_DOMAIN}
# Disable telemetry
ENV NEXT_TELEMETRY_DISABLED=1
ENV DOCKER=true
Expand Down
1 change: 1 addition & 0 deletions apps/main/src/blocks/analytics/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dynamic from 'next/dynamic';

// TODO: Make it SSR friendly
const AnalyticsBlock = dynamic(
() => import(/* webpackChunkName: "analytics-block"*/ './analytics'),
{
Expand Down
9 changes: 8 additions & 1 deletion apps/main/src/pages/analytics/[domain].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ type PathParams = {
};

export const getStaticPaths: GetStaticPaths<PathParams> = async () => {
if (process.env.DOCKER) {
return {
paths: [],
fallback: 'blocking',
};
}
// TODO: only generated a subset of analytics pages
const paths = await getAllProjectStaticPathsByDomain();

return { paths, fallback: true };
return { paths, fallback: 'blocking' };
};

export const getStaticProps: GetStaticProps<
Expand Down
11 changes: 8 additions & 3 deletions apps/main/src/pages/blog/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,21 @@ type PathParam = {
};

export const getStaticPaths: GetStaticPaths<PathParam> = async () => {
if (process.env.DOCKER) {
return {
paths: [],
fallback: 'blocking',
};
}
const fileStructures = await getAllFileStructures(CONTAINER_FOLDER);
const payload = {
return {
paths: fileStructures.map((f) => ({
params: {
slug: [...(f.ancestors || []), f.slug].filter(Boolean),
},
})),
fallback: true,
fallback: 'blocking',
};
return payload;
};

export const getStaticProps: GetStaticProps<
Expand Down
11 changes: 8 additions & 3 deletions apps/main/src/pages/docs/[[...slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,21 @@ type PathParam = {
};

export const getStaticPaths: GetStaticPaths<PathParam> = async () => {
if (process.env.DOCKER) {
return {
paths: [],
fallback: 'blocking',
};
}
const fileStructures = await getAllFileStructures(CONTAINER_FOLDER);
const payload = {
return {
paths: fileStructures.map((f) => ({
params: {
slug: [...(f.ancestors || []), f.slug].filter(Boolean),
},
})),
fallback: true,
fallback: 'blocking',
};
return payload;
};

export const getStaticProps: GetStaticProps<DocsProps, PathParam> = async ({
Expand Down
11 changes: 10 additions & 1 deletion apps/main/src/pages/play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export default function PlayGround(): JSX.Element {
<Alert
type="info"
title="Feel free to play around"
content="We remove stale comments every 24 hours automatically."
content={
process.env.DOCKER
? `We don't remove comment automatically`
: 'We remove stale comments every 24 hours automatically.'
}
onClickDismiss={() => setShowAlert(false)}
hideDismissButton
/>
Expand All @@ -40,6 +44,11 @@ type StaticProps = {
export const getStaticProps: GetStaticProps<StaticProps> = async (): Promise<
GetStaticPropsResult<StaticProps>
> => {
if (process.env.DOCKER) {
return {
props: {},
};
}
const beforeDate = cpDayjs()
.subtract(1, isENVDev ? 'hour' : 'day')
.toISOString();
Expand Down
11 changes: 8 additions & 3 deletions apps/main/src/pages/theme/[domain].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ type PathParams = {
};

export const getStaticPaths: GetStaticPaths<PathParams> = async () => {
if (process.env.DOCKER) {
return {
paths: [],
fallback: 'blocking',
};
}
// TODO: only generated a subset of theme pages to improve build perf
const paths = await getAllProjectStaticPathsByDomain();

// We'll pre-render only these paths at build time.
// { fallback: false } means other routes should 404.
return { paths, fallback: true };
return { paths, fallback: 'blocking' };
};

type StaticProps = {
Expand Down
8 changes: 7 additions & 1 deletion apps/main/src/pages/widget/comment/[pageURL].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ const client = getAdminGqlClient();

// Get all project then prerender all their page comments
export const getStaticPaths: GetStaticPaths<PathParams> = async () => {
if (process.env.DOCKER) {
return {
paths: [],
fallback: 'blocking',
};
}
const freshPages = await query(
FreshPagesDocument,
{
Expand All @@ -106,7 +112,7 @@ export const getStaticPaths: GetStaticPaths<PathParams> = async () => {

// We'll pre-render only these paths at build time.
// { fallback: false } means other routes should 404.
return { paths, fallback: true };
return { paths, fallback: 'blocking' };
};

type StaticProps = PathParams &
Expand Down
6 changes: 6 additions & 0 deletions apps/main/src/pages/widget/comment/timeline/[commentId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ type StaticProps = PathParams &
};

export const getStaticPaths: GetStaticPaths<PathParams> = async () => {
if (process.env.DOCKER) {
return {
paths: [],
fallback: 'blocking',
};
}
const comments = await query(
CommentsDocument,
{
Expand Down
35 changes: 18 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
version: '3'

# Test docker build
services:
chirpy-main:
container_name: chirpy-main
image: devrsi0n/chirpy
build:
context: ./
dockerfile: Dockerfile
# Don't put any sensitive key to build-args, as they'll be exposed to build history, https://github.com/docker/build-push-action/blob/master/docs/advanced/secrets.md
args:
NEXT_PUBLIC_HASURA_HTTP_ORIGIN: http://host.docker.internal:8080/v1/graphql
NEXT_PUBLIC_HASURA_WS_ORIGIN: ws://host.docker.internal:8080/v1/graphql
NEXT_PUBLIC_APP_URL: ${NEXT_PUBLIC_APP_URL}
NEXT_PUBLIC_VAPID: ${NEXT_PUBLIC_VAPID}
NEXT_PUBLIC_APP_URL: http://localhost:3000
NEXT_PUBLIC_ANALYTICS_DOMAIN: ${NEXT_PUBLIC_ANALYTICS_DOMAIN}
NEXTAUTH_URL: ${NEXTAUTH_URL}
HASURA_ADMIN_SECRET: ${HASURA_ADMIN_SECRET}
HASURA_EVENT_SECRET: ${HASURA_EVENT_SECRET}
HASH_ALGORITHM: ${HASH_ALGORITHM}
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
PRIVATE_VAPID: ${PRIVATE_VAPID}
EMAIL_API_KEY: ${EMAIL_API_KEY}
GITHUB_CLIENT_ID: ${GITHUB_CLIENT_ID}
GITHUB_CLIENT_SECRET: ${GITHUB_CLIENT_SECRET}
TWITTER_CONSUMER_KEY: ${TWITTER_CONSUMER_KEY}
TWITTER_CONSUMER_SECRET: ${TWITTER_CONSUMER_SECRET}
NEXTAUTH_URL: http://localhost:3000
environment:
NEXT_PUBLIC_HASURA_HTTP_ORIGIN: http://127.0.0.1:8080/v1/graphql
NEXT_PUBLIC_HASURA_WS_ORIGIN: ws://127.0.0.1:8080/v1/graphql
NEXT_PUBLIC_APP_URL: http://localhost:3000
NEXT_PUBLIC_VAPID: ${NEXT_PUBLIC_VAPID}
NEXT_PUBLIC_ANALYTICS_DOMAIN: ${NEXT_PUBLIC_ANALYTICS_DOMAIN}
NEXTAUTH_URL: http://localhost:3000
HASURA_ADMIN_SECRET: ${HASURA_ADMIN_SECRET}
HASURA_EVENT_SECRET: ${HASURA_EVENT_SECRET}
HASH_ALGORITHM: ${HASH_ALGORITHM}
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
PRIVATE_VAPID: ${PRIVATE_VAPID}
EMAIL_API_KEY: ${EMAIL_API_KEY}
GITHUB_CLIENT_ID: ${GITHUB_CLIENT_ID}
GITHUB_CLIENT_SECRET: ${GITHUB_CLIENT_SECRET}
TWITTER_CONSUMER_KEY: ${TWITTER_CONSUMER_KEY}
TWITTER_CONSUMER_SECRET: ${TWITTER_CONSUMER_SECRET}
restart: always
ports:
- 3000:3000
Expand All @@ -35,8 +38,6 @@ services:
# networks:
# - my_network

# Add more containers below (nginx, postgres, etc.)

# Define a network, which allows containers to communicate
# with each other, by using their container name as a hostname
# networks:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"changeset": "changeset",
"version-packages": "changeset version",
"release": "turbo run build --filter=@chirpy-dev/main-app... && changeset publish",
"build:local": "docker system prune -af && dotenv -e ./apps/main/.env.local docker compose build",
"start:local": "dotenv -e ./apps/main/.env.local docker compose up",
"build:docker:local": "docker system prune -af && dotenv -e ./apps/main/.env.local docker compose build",
"start:docker:local": "dotenv -e ./apps/main/.env.local docker compose up",
"debug": "docker run -it --entrypoint=/bin/bash chirpy-chirpy-main -i"
},
"engines": {
Expand Down

0 comments on commit f62f760

Please sign in to comment.