Skip to content

Commit

Permalink
build: improve building and resulting code
Browse files Browse the repository at this point in the history
  • Loading branch information
JustSamuel committed Nov 9, 2024
1 parent 4e1163c commit d7641ec
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 143 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ dist
.yarn/install-state.gz
.pnp.*

# yarn v4
.yarn/*
!.yarn/releases
!.yarn/plugins
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
26 changes: 16 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
FROM node:alpine AS builder
FROM node:22-alpine AS base
ENV NODE_ENV=development
ENV YARN_VERSION=4.5.1
RUN corepack enable && corepack prepare yarn@${YARN_VERSION}
RUN apk add git

FROM base AS builder
WORKDIR /app
COPY package.json yarn.lock .yarnrc.yml ./
# COPY .yarn ./.yarn
RUN yarn install --immutable

COPY package.json yarn.lock ./
RUN apk add --no-cache git
RUN yarn install --frozen-lockfile
COPY ./src ./src
COPY ./tsconfig.json ./

RUN yarn build

FROM node:alpine
FROM node:alpine AS runner

WORKDIR /app

COPY --from=builder /app/node_modules ./node_modules
COPY package.json yarn.lock ./
COPY . .

COPY --from=builder /app/dist ./dist
COPY ./cronjob /etc/crontabs/root
RUN touch /var/log/cron.log

CMD ["sh", "-c", "crond && tail -f /dev/null"]
CMD ["sh", "-c", "crond && tail -f /var/log/cron.log"]
2 changes: 1 addition & 1 deletion cronjob
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0 * * * * yarn start >> /var/log/cron.log 2>&1
0 * * * * node /app/dist/src/index.js >> /var/log/cron.log 2>&1
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Planka API service",
"main": "src/index.ts",
"scripts": {
"start": "ts-node src/index.ts",
"start:env": "ts-node -r dotenv/config src/index.ts",
"start": "node dist/src/index.js",
"dev": "ts-node src/index.ts",
"build": "tsc",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
Expand All @@ -22,9 +22,9 @@
"@types/imapflow": "^1.0.19",
"@types/node": "^22.9.0",
"dotenv": "^16.0.0",
"prettier": "^3.3.3",
"ts-node": "^10.9.2",
"typescript": "^5.2.2",
"prettier": "^3.3.3"
"typescript": "^5.2.2"
},
"repository": {
"type": "git",
Expand All @@ -36,5 +36,5 @@
"url": "https://github.com/GEWIS/plankapi/issues"
},
"homepage": "https://github.com/GEWIS/plankapi#readme",
"packageManager": "yarn@1.22.22"
"packageManager": "yarn@1.22.19"
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { config } from 'dotenv';
config();

import Mailer from './mailer';

Check warning on line 4 in src/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint / build-and-lint-yarn

Import in body of module; reorder to top
import Planka from './planka';

Check warning on line 5 in src/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint / build-and-lint-yarn

Import in body of module; reorder to top

Expand Down
Loading

0 comments on commit d7641ec

Please sign in to comment.