From 97c1a160ad3e84e2a6143239614fde27d1c7e43a Mon Sep 17 00:00:00 2001 From: Kakious Date: Fri, 22 Nov 2024 21:25:20 -0500 Subject: [PATCH] feat: docker image building --- .forgejo/workflows/release.yml | 41 ++++++++++++++++++++++++++++++++ Dockerfile | 24 +++++++++++++++++++ apps/backend/package.json | 4 ++-- apps/frontend/src/app/layout.tsx | 28 ++++++++++------------ apps/frontend/src/app/page.tsx | 4 ++-- package.json | 3 ++- 6 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 Dockerfile diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml index e69de29..ded5493 100644 --- a/.forgejo/workflows/release.yml +++ b/.forgejo/workflows/release.yml @@ -0,0 +1,41 @@ +on: [push] +jobs: + build: + runs-on: docker + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to git.kakio.us + uses: docker/login-action@v3.3.0 + with: + registry: git.kakio.us + username: kakious + password: ${{ secrets.REPO_PUSH }} + + - name: Build and push frontend + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + target: frontend + tags: | + git.kakio.us/kakious/authcore-frontend:latest + git.kakio.us/kakious/authcore-frontend:${{ github.sha }} + + - name: Build and push backend + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + target: backend + tags: | + git.kakio.us/kakious/authcore-backend:latest + git.kakio.us/kakious/authcore-backend:${{ github.sha }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9e3debf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM node:22-slim AS base +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN corepack enable + +FROM base AS build +COPY . /usr/src/app +WORKDIR /usr/src/app +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile +RUN pnpm run -r build +RUN pnpm deploy --filter=backend --prod /prod/backend +RUN pnpm deploy --filter=frontend --prod /prod/frontend + +FROM base AS backend +COPY --from=build /prod/backend /usr/src/app +WORKDIR /usr/src/app +EXPOSE 3001 +CMD ["pnpm", "start"] + +FROM base AS frontend +COPY --from=build /prod/frontend /usr/src/app +WORKDIR /usr/src/app +EXPOSE 3000 +CMD ["pnpm", "start"] \ No newline at end of file diff --git a/apps/backend/package.json b/apps/backend/package.json index fc41e35..56d0302 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -1,5 +1,5 @@ { - "name": "waterwolf-oauth-core", + "name": "backend", "version": "0.0.1", "description": "", "author": "", @@ -114,4 +114,4 @@ "testEnvironment": "node" }, "packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903" -} \ No newline at end of file +} diff --git a/apps/frontend/src/app/layout.tsx b/apps/frontend/src/app/layout.tsx index a36cde0..2807dd2 100644 --- a/apps/frontend/src/app/layout.tsx +++ b/apps/frontend/src/app/layout.tsx @@ -1,21 +1,21 @@ -import type { Metadata } from "next"; -import localFont from "next/font/local"; -import "./globals.css"; +import type { Metadata } from 'next'; +import localFont from 'next/font/local'; +import './globals.css'; const geistSans = localFont({ - src: "./fonts/GeistVF.woff", - variable: "--font-geist-sans", - weight: "100 900", + src: './fonts/GeistVF.woff', + variable: '--font-geist-sans', + weight: '100 900', }); const geistMono = localFont({ - src: "./fonts/GeistMonoVF.woff", - variable: "--font-geist-mono", - weight: "100 900", + src: './fonts/GeistMonoVF.woff', + variable: '--font-geist-mono', + weight: '100 900', }); export const metadata: Metadata = { - title: "Create Next App", - description: "Generated by create next app", + title: 'Create Next App', + description: 'Generated by create next app', }; export default function RootLayout({ @@ -25,11 +25,7 @@ export default function RootLayout({ }>) { return ( - - {children} - + {children} ); } diff --git a/apps/frontend/src/app/page.tsx b/apps/frontend/src/app/page.tsx index 6fe62d1..0b4199e 100644 --- a/apps/frontend/src/app/page.tsx +++ b/apps/frontend/src/app/page.tsx @@ -1,4 +1,4 @@ -import Image from "next/image"; +import Image from 'next/image'; export default function Home() { return ( @@ -14,7 +14,7 @@ export default function Home() { />
  1. - Get started by editing{" "} + Get started by editing{' '} src/app/page.tsx diff --git a/package.json b/package.json index a1f9c0d..de8c863 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "dev": "pnpm run --parallel dev" + "dev": "pnpm run --parallel dev", + "build": "pnpm run --parallel build" }, "keywords": [], "author": "",