Skip to content

Commit

Permalink
Docker file seems to work.
Browse files Browse the repository at this point in the history
  • Loading branch information
YaytayAtWork committed Jul 16, 2024
1 parent b781e13 commit 0b1be47
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 11 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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#<meta name="version" content="" />#<meta name="version" content="'$GITHUB_REF'@'$GITHUB_SHA'" />#' index.html
sed -i 's#<span>0.0.0</span>#<span>$GITHUB_REF</span>#' src/Version.tsx
grep version index.html
npm ci
npx tsc --noEmit
Expand All @@ -39,4 +44,14 @@ jobs:
with:
name: build
path: |
build.tar.gz
build.tar.gz
- name: Build server
run: |
cd server
npm ci
npx tsc --noEmit
- name: Build image
run: |
docker build .
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="version" content="" />
<title>Swarm View</title>
</head>
<body>
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions server/server-prod.js → server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -82,7 +83,7 @@ function App() {
<Box id="navbar" className="sidebar" borderRight='2px solid' borderColor="gray" >
<Box sx={{ padding: '2px' }}>
<Typography variant='h6'>Swarm View</Typography>
<Typography variant='body2'>Version 0.0.0</Typography>
<Typography variant='body2'>Version <Version/></Typography>
</Box>

<hr />
Expand Down
2 changes: 0 additions & 2 deletions src/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ function Section(props: SectionProps) {
</Accordion>
</Grid>
)


}

export default Section;
8 changes: 8 additions & 0 deletions src/Version.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

function Version() {

return <span>0.0.0</span>

}

export default Version

0 comments on commit 0b1be47

Please sign in to comment.