Skip to content

Commit

Permalink
Production dockerfile (#4)
Browse files Browse the repository at this point in the history
+ Add `Dockerfile.production`
  • Loading branch information
seheon99 authored Oct 29, 2023
2 parents 9524241 + 59c3a49 commit 9ec1843
Show file tree
Hide file tree
Showing 30 changed files with 1,442 additions and 1,594 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./yarn
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"recommendations": [
"arcanis.vscode-zipfs",
"dbaeumer.vscode-eslint"
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
},
"eslint.nodePath": ".yarn/sdks",
"typescript.tsdk": ".yarn/sdks/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
"typescript.enablePromptUseWorkspaceTsdk": true,
"prettier.prettierPath": ".yarn/sdks/prettier/index.cjs"
}
874 changes: 0 additions & 874 deletions .yarn/releases/yarn-3.6.4.cjs

This file was deleted.

20 changes: 20 additions & 0 deletions .yarn/sdks/eslint/lib/unsupported-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const {existsSync} = require(`fs`);
const {createRequire} = require(`module`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.cjs";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = createRequire(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require eslint/use-at-your-own-risk
require(absPnpApiPath).setup();
}
}

// Defer to the real eslint/use-at-your-own-risk your application uses
module.exports = absRequire(`eslint/use-at-your-own-risk`);
12 changes: 10 additions & 2 deletions .yarn/sdks/eslint/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"name": "eslint",
"version": "8.45.0-sdk",
"version": "8.52.0-sdk",
"main": "./lib/api.js",
"type": "commonjs"
"type": "commonjs",
"bin": {
"eslint": "./bin/eslint.js"
},
"exports": {
"./package.json": "./package.json",
".": "./lib/api.js",
"./use-at-your-own-risk": "./lib/unsupported-api.js"
}
}
20 changes: 20 additions & 0 deletions .yarn/sdks/prettier/bin/prettier.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const {existsSync} = require(`fs`);
const {createRequire} = require(`module`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.cjs";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = createRequire(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require prettier/bin/prettier.cjs
require(absPnpApiPath).setup();
}
}

// Defer to the real prettier/bin/prettier.cjs your application uses
module.exports = absRequire(`prettier/bin/prettier.cjs`);
File renamed without changes.
5 changes: 3 additions & 2 deletions .yarn/sdks/prettier/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "prettier",
"version": "3.0.0-sdk",
"main": "./index.js",
"type": "commonjs"
"main": "./index.cjs",
"type": "commonjs",
"bin": "./bin/prettier.cjs"
}
6 changes: 3 additions & 3 deletions .yarn/sdks/typescript/lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const absRequire = createRequire(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require typescript/lib/typescript.js
// Setup the environment to be able to require typescript
require(absPnpApiPath).setup();
}
}

// Defer to the real typescript/lib/typescript.js your application uses
module.exports = absRequire(`typescript/lib/typescript.js`);
// Defer to the real typescript your application uses
module.exports = absRequire(`typescript`);
6 changes: 5 additions & 1 deletion .yarn/sdks/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"name": "typescript",
"version": "5.0.4-sdk",
"main": "./lib/typescript.js",
"type": "commonjs"
"type": "commonjs",
"bin": {
"tsc": "./bin/tsc",
"tsserver": "./bin/tsserver"
}
}
1 change: 0 additions & 1 deletion .yarnrc.yml

This file was deleted.

8 changes: 8 additions & 0 deletions Dockerfile.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:18
WORKDIR /app
COPY package.json yarn.lock ./*.yml ./*.yaml ./*.config.js ./*.json ./
COPY ./.yarn/releases ./.yarn/releases
RUN yarn
COPY ./src ./src
COPY ./public ./public
CMD ["yarn", "run", "dev"]
50 changes: 50 additions & 0 deletions Dockerfile.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM node:21-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 git
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* ./
RUN \
corepack enable && \
yarn set version from sources && \
yarn install

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/.yarn ./.yarn
COPY . .
RUN yarn build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# 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
ENV HOSTNAME "0.0.0.0"

CMD ["node", "server.js"]
10 changes: 10 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
nextjs:
ports:
- 80:3000
build:
context: .
dockerfile: Dockerfile
volumes:
- ./src:/app/src:ro
- ./public:/app/public:ro
12 changes: 6 additions & 6 deletions eslint-results.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@
"artifacts": [
{
"location": {
"uri": "file:///C:/Users/seheon/Documents/GitHub/gifthub-web/next-env.d.ts"
"uri": "next-env.d.ts"
}
},
{
"location": {
"uri": "file:///C:/Users/seheon/Documents/GitHub/gifthub-web/next.config.js"
"uri": "next.config.js"
}
},
{
"location": {
"uri": "file:///C:/Users/seheon/Documents/GitHub/gifthub-web/postcss.config.js"
"uri": "postcss.config.js"
}
},
{
"location": {
"uri": "file:///C:/Users/seheon/Documents/GitHub/gifthub-web/src/app/layout.tsx"
"uri": "src/app/layout.tsx"
}
},
{
"location": {
"uri": "file:///C:/Users/seheon/Documents/GitHub/gifthub-web/src/app/page.tsx"
"uri": "src/app/page.tsx"
}
},
{
"location": {
"uri": "file:///C:/Users/seheon/Documents/GitHub/gifthub-web/tailwind.config.js"
"uri": "tailwind.config.js"
}
}
],
Expand Down
13 changes: 11 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
const nextConfig = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'cdn.gifthub.kr',
},
],
},
};

module.exports = nextConfig
module.exports = nextConfig;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
"lint": "next lint"
},
"dependencies": {
"@tailwindcss/forms": "^0.5.6",
"autoprefixer": "10.4.14",
"next": "13.4.7",
"postcss": "8.4.24",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "^4.10.1",
"react-hook-form": "^7.47.0",
"react-icons": "^4.11.0",
"return-fetch": "^0.4.5",
"tailwindcss": "3.3.2",
"typescript": "5.0.4"
Expand Down
Binary file added public/dahyeon.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion public/next.svg

This file was deleted.

1 change: 0 additions & 1 deletion public/vercel.svg

This file was deleted.

43 changes: 43 additions & 0 deletions src/apis/giftcards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { http } from './http';

export interface GetGiftcard {
senderProfile: string;
senderName: string;
message: string;
productImage: string;
productName: string;
brandImage: string;
brandName: string;
expirationDate: string;
}

async function getGiftcard(
uuid: string,
password: string,
): Promise<GetGiftcard> {
try {
const response = await http.get(`/giftcards/${uuid}`, {
headers: {
Authorization: `Basic ${atob(password)}`,
},
});
return await response.json();
} catch {
return {
senderProfile: '/dahyeon.jpeg',
senderName: uuid,
message: password,
productImage: '/dahyeon.jpeg',
productName: '아이스 카페 아메리카노 T',
brandImage: '/dahyeon.jpeg',
brandName: '스타벅스',
expirationDate: '2023-07-25',
};
}
}

const GiftcardApi = {
getGiftcard,
};

export default GiftcardApi;
26 changes: 26 additions & 0 deletions src/apis/http.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import returnFetch from 'return-fetch';

const instance = returnFetch({
baseUrl: 'https://api.dev.gifthub.kr',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
});

const http = {
get: function (url: string, options?: RequestInit) {
return instance(url, {
method: 'GET',
...options,
});
},
post: function (url: string, options?: RequestInit) {
return instance(url, {
method: 'POST',
...options,
});
},
};

export { http };
11 changes: 0 additions & 11 deletions src/apis/instance.ts

This file was deleted.

Loading

0 comments on commit 9ec1843

Please sign in to comment.