From 0b1be47e693f9dca78ede5023b8e5cd8e86a569e Mon Sep 17 00:00:00 2001 From: Jim Talbut Date: Tue, 16 Jul 2024 05:20:58 +0100 Subject: [PATCH] Docker file seems to work. --- .github/workflows/node.js.yml | 21 ++++++++++++++++++--- Dockerfile | 26 ++++++++++++++++++++++++++ index.html | 1 + package.json | 4 +--- server/{server-prod.js => server.js} | 4 ++-- src/App.tsx | 3 ++- src/Section.tsx | 2 -- src/Version.tsx | 8 ++++++++ 8 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 Dockerfile rename server/{server-prod.js => server.js} (77%) create mode 100644 src/Version.tsx diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index d9c53d9..af2581b 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -20,14 +20,19 @@ jobs: # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} cache: 'npm' - - run: | + + - name: Build UI + run: | sed -i 's###' index.html + sed -i 's#0.0.0#$GITHUB_REF#' src/Version.tsx grep version index.html npm ci npx tsc --noEmit @@ -39,4 +44,14 @@ jobs: with: name: build path: | - build.tar.gz \ No newline at end of file + build.tar.gz + + - name: Build server + run: | + cd server + npm ci + npx tsc --noEmit + + - name: Build image + run: | + docker build . \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5c97b4f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM chainguard/node:latest-dev + +WORKDIR /app + +COPY --chown=node:node package.json package-lock.json *.html *.js* *.ts /app/ +COPY --chown=node:node src /app/src +COPY --chown=node:node server /app/server + +RUN ls -l \ + && npm install \ + && npm ci + +ENV NODE_ENV=production + +RUN ls -l \ + && npm run build --if-present \ + && cd /app/server \ + && npm ci \ + && cd .. \ + && ls -l + +FROM chainguard/node:latest +COPY --from=0 /app/server /app +COPY --from=0 /app/dist /app/dist + +CMD [ "server.js" ] \ No newline at end of file diff --git a/index.html b/index.html index 814730d..d0beec0 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,7 @@ + Swarm View diff --git a/package.json b/package.json index 7bec7df..ba7ec86 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,7 @@ "main": "server/index.js", "scripts": { "dev": "node server-dev.js", - "build:client": "vite build --outDir dist/client", - "build:server": "vite build --ssr src/entry-server.jsx --outDir dist/server", - "build": "npm run build:client && npm run build:server", + "build": "vite build --outDir dist", "serve": "node server-prod.js", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0" }, diff --git a/server/server-prod.js b/server/server.js similarity index 77% rename from server/server-prod.js rename to server/server.js index 7f60321..26eb258 100644 --- a/server/server-prod.js +++ b/server/server.js @@ -8,11 +8,11 @@ import apiRouter from './apiRouter.js'; const app = express(); app.use(apiRouter) -app.use(express.static(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../dist/client'), { index: false })); +app.use(express.static(path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'dist'), { index: false })); app.use('*', async (_, res) => { try { - const template = fs.readFileSync('../dist/client/index.html', 'utf-8'); + const template = fs.readFileSync('dist/index.html', 'utf-8'); res.status(200).set({ 'Content-Type': 'text/html' }).end(template); } catch (error) { res.status(500).end(error.toString()); diff --git a/src/App.tsx b/src/App.tsx index 8eebb57..166a7db 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -30,6 +30,7 @@ import NodeUi from './Node'; import TaskUi from './Task'; import SecretUi from './Secret'; import ConfigUi from './Config'; +import Version from './Version'; import Stack from '@mui/material/Stack'; import { PaletteMode } from '@mui/material'; @@ -82,7 +83,7 @@ function App() { Swarm View - Version 0.0.0 + Version
diff --git a/src/Section.tsx b/src/Section.tsx index 2fffe40..f47231e 100644 --- a/src/Section.tsx +++ b/src/Section.tsx @@ -44,8 +44,6 @@ function Section(props: SectionProps) { ) - - } export default Section; \ No newline at end of file diff --git a/src/Version.tsx b/src/Version.tsx new file mode 100644 index 0000000..70960f1 --- /dev/null +++ b/src/Version.tsx @@ -0,0 +1,8 @@ + +function Version() { + + return 0.0.0 + +} + +export default Version \ No newline at end of file