Skip to content

Commit

Permalink
setup CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoishin committed Jan 7, 2024
1 parent 179a72c commit 76c5ac9
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 2 deletions.
File renamed without changes.
50 changes: 50 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Publish

on:
push:
branches:
- main

permissions:
packages: write

jobs:
docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=sha
- uses: docker/build-push-action@v5
with:
context: ./projects/server
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

upload-assets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: package.json
- run: npm ci
- run: npm run build
- uses: actions/upload-artifact@v4
with:
name: admin
path: ./projects/admin/dist
- uses: actions/upload-artifact@v4
with:
name: client
path: ./projects/client/dist
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ web_modules/
.yarn-integrity

# dotenv environment variable files
.env
# .env
.env.development.local
.env.test.local
.env.production.local
Expand Down
1 change: 1 addition & 0 deletions projects/server/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"
39 changes: 39 additions & 0 deletions projects/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM node:20-slim AS base

RUN apt-get update && apt-get install -y openssl && rm -rf /var/lib/apt/lists/*


FROM base AS build

WORKDIR /app

COPY package.json tsconfig.json ./
COPY prisma prisma
COPY src src

RUN npm install
RUN npx prisma generate
RUN npm run build


FROM base AS node_modules

WORKDIR /app

COPY package.json ./
RUN npm install --omit=dev


FROM base

WORKDIR /app

COPY bin.js package.json ./
COPY --from=build /app/out out
COPY --from=node_modules /app/node_modules node_modules
COPY --from=build /app/node_modules/.prisma node_modules/.prisma
COPY --from=build /app/node_modules/@prisma/client node_modules/@prisma/client

ENV NODE_ENV=production

CMD ["npm", "start"]
14 changes: 13 additions & 1 deletion projects/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@trpc/server/adapters/fastify";
import { appRouter, type AppRouter } from "./router.js";
import { createContext } from "./context.js";
import { prisma } from "./prisma.js";

const server = fastify({
maxParamLength: 5_000,
Expand All @@ -28,6 +29,17 @@ await server.register(fastifyTRPCPlugin, {
},
} satisfies FastifyTRPCPluginOptions<AppRouter>);

await server.listen({ port: 3000 });
// Healthcheck endpoint
server.get("/", async (_, res) => {
try {
await prisma.$executeRaw`SELECT 1;`;
return { ok: true };
} catch (error) {
console.error(error);
return res.status(500).send();
}
});

await server.listen({ port: 3000, host: "0.0.0.0" });

console.log("server listening on port 3000");

0 comments on commit 76c5ac9

Please sign in to comment.