Skip to content

v1.0.0 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules/
dist/
output/
.vscode
.dockerignore
Dockerfile
*.zip
*.rar
*.tgz
*.txt
*.json

!package.json
!package-lock.json
!tsconfig.json
33 changes: 33 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run Tests

on:
push:
branches-ignore:
- 'main'

jobs:
lint-app:
name: Test App
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3

- name: Use NodeJS v20.15.0
uses: actions/setup-node@v3
with:
node-version: 20.15.0
registry-url: https://registry.npmjs.org/

- name: Install Dependencies
run: npm install

- name: Lint
run: npm run lint

- name: Transpile
run: npm run transpile

- name: Test
run: npm test

32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM node:20.15.0-alpine AS base
RUN mkdir -p /opt/app
WORKDIR /opt/app
RUN addgroup -S user && adduser -S user -G user
RUN chown -R user:user /opt/app
COPY package*.json ./

# BUILD TARGET
FROM base AS build
RUN npm install
COPY . ./
RUN npm run transpile

# DEVELOPMENT TARGET PROFILE
FROM base AS development
RUN npm install
COPY . ./
RUN mkdir /opt/app/node_modules/.vite \
&& chown -R user:user /opt/app/node_modules/.vite
USER user
EXPOSE 9229
CMD ["sh"]

# PRODUCTION TARGET PROFILE
FROM base AS production
ENV NODE_ENV=production
COPY --from=build /opt/app/dist /opt/app/dist
COPY package*.json ./
RUN npm install && npm prune --production
USER user
EXPOSE 9229
CMD ["sh"]
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Solutions for [Advent of Code](https://adventofcode.com/) event puzzles.

## Usage

Using Node

1. Run a TypeScript file inside the **/src** directory. For example:

```
Expand All @@ -35,12 +37,44 @@ Solutions for [Advent of Code](https://adventofcode.com/) event puzzles.
```
3. See the [Available Scripts](#available-scripts) section for more information.

## Alternate Usage

Using Docker

- Build the image
```
docker compose -f docker-compose.dev.yml build
```

- Transpile the TypeScript files to JavaScript (PowerShell)
```
docker run -it -v ${pwd}:/opt/app -v /opt/app/node_modules --rm weaponsforge/adventofcode:dev npm run transpile
```

- Run tests (PowerShell)
```
docker run -it -v ${pwd}:/opt/app -v /opt/app/node_modules --rm weaponsforge/adventofcode:dev npm test
```

- Watch TS file updates: Use available scripts - `npm run watch`, `npm run watch:docker:win`
```
docker run -it -v ${pwd}:/opt/app -v /opt/app/node_modules --rm weaponsforge/adventofcode:dev <AVAILABLE_SCRIPT>
```

## Available Scripts

### `npm run dev`

Runs `vitest` in watch mode, watching file changes and errors to files linked with `*.test.ts` files.

### `npm run watch`

Watches file changes in `.ts` files using the `tsc --watch` option.

### `npm run watch:docker:win`

Watches file changes in `.ts` files using the `tsc --watch` option with `dynamicPriorityPolling` in Docker containers running in Windows WSL2.

### `npm run dev:debug`

Runs the sample TS script.
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
weaponsforge.adventofcode-dev:
container_name: weaponsforge-adventofcode-dev
image: weaponsforge/adventofcode:dev
build:
context: .
dockerfile: Dockerfile
target: development
volumes:
- .:/opt/app
- /opt/app/node_modules
ports:
- "9229:9229"
stdin_open: true
tty: true
15 changes: 15 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
weaponsforge.adventofcode:
container_name: weaponsforge-adventofcode
image: weaponsforge/adventofcode:latest
build:
context: .
dockerfile: Dockerfile
target: production
volumes:
- ./output:/opt/app/output
- /opt/app/node_modules
ports:
- "9229:9229"
stdin_open: true
tty: true
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"dev": "vitest",
"dev:debug": "vite-node src/sample/sample.ts",
"transpile": "tsc -p tsconfig.json && tsc-alias",
"watch": "tsc -p tsconfig.json --watch",
"watch:docker:win": "tsc -p tsconfig.json --watch --watchFile dynamicPriorityPolling --watchDirectory dynamicPriorityPolling",
"lint": "eslint \"src/**/*.ts\" *.mjs *.ts",
"lint:fix": "eslint \"src/**/*.ts\" *.mjs *.ts --fix",
"test": "vitest run"
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
]
}
},
"watchOptions": {
// "watchFile": "dynamicPriorityPolling"
"excludeDirectories": ["**/node_modules", "dist"]
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
Loading