Skip to content

Commit

Permalink
[optimize] upgrade to Next.js 14 & other Upstream packages
Browse files Browse the repository at this point in the history
[refactor] reduce Docker image size
[add] Health Check configuration of Docker services
[fix] some UI detail bugs
  • Loading branch information
TechQuery committed Nov 26, 2023
1 parent 6128c8f commit 8fb6da9
Show file tree
Hide file tree
Showing 14 changed files with 1,350 additions and 1,479 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
packages: write
contents: read
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Inject Environment variables
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }}

- name: Deploy to Vercel
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto-install-peers = false
30 changes: 16 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
FROM node:18-slim
# Reference: https://pnpm.io/docker#example-1-build-a-bundle-in-a-docker-container

USER root
FROM node:18-slim AS base
RUN apt-get update && \
apt-get install curl -y --no-install-recommends
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY . /app
WORKDIR /app

RUN npm rm yarn -g
RUN npm i pnpm -g
FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm i --prod --frozen-lockfile

RUN mkdir /home/node/app
WORKDIR /home/node/app

COPY package.json pnpm-lock.yaml /home/node/app/
RUN pnpm i --frozen-lockfile

COPY . /home/node/app
FROM base AS build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm i --frozen-lockfile
RUN pnpm build

RUN pnpm prune --prod || true \
pnpm store prune

FROM base
COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=build /app/dist /app/dist
EXPOSE 3000
CMD ["npm", "start"]
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

[React][1] project scaffold based on [TypeScript][2], [Next.js][3], [Bootstrap][4] & [Workbox][5]. And this project bootstrapped with [`create-next-app`][6].

[![NPM Dependency](https://david-dm.org/idea2app/next-bootstrap-ts.svg)][7]
[![CI & CD](https://github.com/idea2app/Next-Bootstrap-ts/actions/workflows/main.yml/badge.svg)][8]
[![CI & CD](https://github.com/idea2app/idea2app.github.io/actions/workflows/main.yml/badge.svg)][8]

## Technology stack

- Language: [TypeScript v5][2]
- Component engine: [Nextjs v13][3]
- Component engine: [Nextjs v14][3]
- Component suite: [Bootstrap v5][4]
- PWA framework: [Workbox v6][5]
- State management: [MobX v6][9]
Expand Down Expand Up @@ -61,9 +60,8 @@ pnpm container
[4]: https://getbootstrap.com/
[5]: https://developers.google.com/web/tools/workbox
[6]: https://github.com/vercel/next.js/tree/canary/packages/create-next-app
[7]: https://david-dm.org/idea2app/next-bootstrap-ts
[8]: https://github.com/idea2app/Next-Bootstrap-ts/actions/workflows/main.yml
[9]: https://github.com/mobxjs/mobx/tree/mobx4and5/docs
[8]: https://github.com/idea2app/idea2app.github.io/actions/workflows/main.yml
[9]: https://mobx.js.org/
[11]: https://github.com/features/actions
[12]: https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme
[13]: https://nextjs.org/docs/api-routes/introduction
Expand Down
2 changes: 1 addition & 1 deletion components/Git/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GitCard } from './Card';
export const GitListLayout: FC<{ defaultData: GitRepository[] }> = ({
defaultData,
}) => (
<Row as="ul" className="list-unstyled g-4" xs={1} sm={2}>
<Row as="ul" className="list-unstyled g-4" xs={1} md={2} xl={3}>
{defaultData.map(
item =>
!!(item.description && item.topics?.length) && (
Expand Down
2 changes: 1 addition & 1 deletion components/Project/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ProjectCard: FC<ProjectCardProps> = ({
</ul>
</Card.Body>
<Card.Footer className="d-flex">
<strong className="flex-fill">{price + ''}</strong>
<strong className="flex-fill"></strong>

<time>🏁 {formatDate(+settlementDate!, 'YYYY-MM-DD')}</time>
</Card.Footer>
Expand Down
2 changes: 1 addition & 1 deletion components/Project/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ProjectCard } from './Card';
export const ProjectListLayout: FC<{ defaultData: Project[] }> = ({
defaultData,
}) => (
<Row as="ul" className="list-unstyled g-4" xs={1} sm={2} md={3}>
<Row as="ul" className="list-unstyled g-4" xs={1} md={2} lg={3}>
{defaultData.map(item => (
<Col as="li" key={item.id + ''}>
<ProjectCard className="h-100 shadow-sm" {...item} />
Expand Down
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ services:
- 3000:3000
networks:
- idea2app
healthcheck:
test: ['CMD-SHELL', 'curl -f http://localhost:3000/ || exit 1']
interval: 3s
retries: 5
start_period: 30s
labels:
- 'autoheal=true'
restart: always
logging:
driver: 'json-file'
options:
max-size: '10m'

autoheal:
image: willfarrell/autoheal:1.2.0
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: always

caddy:
depends_on:
- next-bootstrap-ts
Expand Down
50 changes: 25 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@
"private": true,
"dependencies": {
"classnames": "^2.3.2",
"file-type": "^18.5.0",
"idea-react": "^1.0.0-rc.22",
"koajax": "^0.8.6",
"file-type": "^18.7.0",
"idea-react": "^1.0.0-rc.30",
"koajax": "^0.9.6",
"lodash": "^4.17.21",
"mobx": "^6.10.1",
"mobx-i18n": "^0.4.1",
"mobx-lark": "^1.0.0-rc.7",
"mobx-react": "^9.0.1",
"mobx-restful": "^0.6.11",
"mobx-restful-table": "^1.1.2",
"next": "^13.4.19",
"next-ssr-middleware": "^0.5.1",
"mobx": "~6.10.2",
"mobx-i18n": "^0.4.2",
"mobx-lark": "^1.0.0-rc.10",
"mobx-react": "~9.0.2",
"mobx-restful": "^0.6.12",
"mobx-restful-table": "^1.2.2",
"next": "^14.0.3",
"next-ssr-middleware": "^0.6.1",
"react": "^18.2.0",
"react-bootstrap": "^2.8.0",
"react-bootstrap": "^2.9.1",
"react-dom": "^18.2.0",
"web-utility": "^4.1.0",
"webpack": "^5.88.2"
"web-utility": "^4.1.3",
"webpack": "^5.89.0"
},
"devDependencies": {
"@octokit/openapi-types": "^18.0.0",
"@types/lodash": "^4.14.197",
"@types/node": "^18.17.12",
"@types/react": "^18.2.21",
"eslint": "^8.48.0",
"eslint-config-next": "^13.4.19",
"@octokit/openapi-types": "^19.0.2",
"@types/lodash": "^4.14.202",
"@types/node": "^18.18.13",
"@types/react": "^18.2.38",
"eslint": "^8.54.0",
"eslint-config-next": "^14.0.3",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "^8.0.3",
"less": "^4.2.0",
"less-loader": "^11.1.3",
"lint-staged": "^14.0.1",
"lint-staged": "^15.1.0",
"next-pwa": "~5.6.0",
"next-with-less": "^3.0.1",
"prettier": "^3.0.3",
"prettier": "^3.1.0",
"ts-node": "^10.9.1",
"typescript": "~5.2.2"
"typescript": "~5.3.2"
},
"prettier": {
"singleQuote": true,
Expand All @@ -59,7 +59,7 @@
"start": "next start",
"lint": "next lint",
"test": "lint-staged && npm run lint",
"pack-image": "docker build -t next-bootstrap-ts:latest .",
"container": "docker rm -f next-bootstrap-ts && docker run --name next-bootstrap-ts -p 3000:3000 -d next-bootstrap-ts:latest"
"pack-image": "docker build -t idea2app/next-bootstrap-ts:latest .",
"container": "docker rm -f next-bootstrap-ts && docker run --name next-bootstrap-ts -p 3000:3000 -d idea2app/next-bootstrap-ts:latest"
}
}
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const AppShell = observer(({ Component, pageProps }: AppProps) => {
bg="white"
variant="light"
fixed="top"
expand="sm"
expand="md"
collapseOnSelect
>
<Container>
Expand Down
4 changes: 2 additions & 2 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export default function Document() {

<link
rel="stylesheet"
href="https://unpkg.com/[email protected].1/dist/css/bootstrap.min.css"
href="https://unpkg.com/[email protected].2/dist/css/bootstrap.min.css"
/>
<link
rel="stylesheet"
href="https://unpkg.com/bootstrap-icons@1.10.5/font/bootstrap-icons.css"
href="https://unpkg.com/bootstrap-icons@1.11.1/font/bootstrap-icons.css"
/>
</Head>

Expand Down
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const HomePage: FC<InferGetServerSidePropsType<typeof getServerSideProps>> =
{t('idea2app_slogan')}
</p>

<Row className="mt-5 g-4" xs={1} sm={2} md={3}>
<Row className="mt-5 g-4" xs={1} lg={3}>
{service().map(({ title, summary, buttonText, buttonLink }) => (
<Col key={title}>
<Card
Expand Down
Loading

1 comment on commit 8fb6da9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for idea2app ready!

✅ Preview
https://idea2app-py6wa7bmh-techquery.vercel.app

Built with commit 8fb6da9.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.