feat(release): Adds docker support
This commit is contained in:
parent
a3c1bae6db
commit
68368ab916
7 changed files with 79 additions and 3 deletions
38
.forgejo/workflows/build-release-container.yaml
Normal file
38
.forgejo/workflows/build-release-container.yaml
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
name: build-container
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- release-*
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: docker
|
||||||
|
steps:
|
||||||
|
- name: Checkout the repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Use Node.JS 20.x
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 20.x
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Run build
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Setup Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
- name: Login to Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: hub.docker.com
|
||||||
|
username: ${{ secrets.DOCKER_USER }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
- name: Build and Push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: neintonine/pnp-scheduler:release
|
||||||
|
context: .
|
||||||
9
Dockerfile
Normal file
9
Dockerfile
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
FROM node:20
|
||||||
|
|
||||||
|
COPY ./dist /app/dist
|
||||||
|
COPY ./node_modules /app/node_modules
|
||||||
|
COPY ./public /app/public
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
CMD sh -c "node /app/dist/deploy.js && node /app/dist/main.js"
|
||||||
9
examples/docker-compose.yml
Normal file
9
examples/docker-compose.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
services:
|
||||||
|
bot:
|
||||||
|
container_name: "pnp_scheduler_bot"
|
||||||
|
image:
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- ./data:/app/data
|
||||||
|
env_file:
|
||||||
|
- ../.env.example
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
"main": "main.ts",
|
"main": "main.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node ./build/build-cli.mjs",
|
"build": "node ./build/build-cli.mjs",
|
||||||
|
"build:docker": "sudo docker build .",
|
||||||
"watch": "node ./build/watch.mjs",
|
"watch": "node ./build/watch.mjs",
|
||||||
"deploy": "node ./dist/deploy.js",
|
"deploy": "node ./dist/deploy.js",
|
||||||
"start": "node ./dist/main.js",
|
"start": "node ./dist/main.js",
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ export class Services {
|
||||||
container.set<Logger>(logger, 'logger');
|
container.set<Logger>(logger, 'logger');
|
||||||
|
|
||||||
const database = new DatabaseConnection(env.database);
|
const database = new DatabaseConnection(env.database);
|
||||||
|
database.connect()
|
||||||
container.set<DatabaseConnection>(database);
|
container.set<DatabaseConnection>(database);
|
||||||
|
|
||||||
const eventHandler = new EventHandler();
|
const eventHandler = new EventHandler();
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,22 @@ import Sqlite3 from "better-sqlite3";
|
||||||
import Database from "better-sqlite3";
|
import Database from "better-sqlite3";
|
||||||
import {Container} from "../Container/Container";
|
import {Container} from "../Container/Container";
|
||||||
import {Logger} from "log4js";
|
import {Logger} from "log4js";
|
||||||
|
import path from "node:path";
|
||||||
|
import * as fs from "node:fs";
|
||||||
|
|
||||||
export class DatabaseConnection {
|
export class DatabaseConnection {
|
||||||
private database: Sqlite3.Database;
|
private database: Sqlite3.Database;
|
||||||
|
|
||||||
constructor(env: DatabaseEnvironment) {
|
constructor(private readonly env: DatabaseEnvironment) {
|
||||||
this.database = new Database(env.path, {
|
}
|
||||||
|
|
||||||
|
public connect() {
|
||||||
|
const directory = path.dirname(this.env.path);
|
||||||
|
fs.mkdirSync(directory, {
|
||||||
|
recursive: true
|
||||||
|
})
|
||||||
|
|
||||||
|
this.database = new Database(this.env.path, {
|
||||||
nativeBinding: "node_modules/better-sqlite3/build/Release/better_sqlite3.node",
|
nativeBinding: "node_modules/better-sqlite3/build/Release/better_sqlite3.node",
|
||||||
})
|
})
|
||||||
this.database.pragma('journal_mode = WAL');
|
this.database.pragma('journal_mode = WAL');
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
import * as fs from "node:fs";
|
||||||
|
import {dot} from "node:test/reporters";
|
||||||
|
|
||||||
type DiscordEnvironment = {
|
type DiscordEnvironment = {
|
||||||
token: string;
|
token: string;
|
||||||
|
|
@ -27,8 +29,14 @@ export class Environment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public setup() {
|
public setup() {
|
||||||
|
const dotenvPath = path.resolve(__dirname, "../environment/.env");
|
||||||
|
|
||||||
|
if (!fs.existsSync(dotenvPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dotenv.config({
|
dotenv.config({
|
||||||
path: path.resolve(__dirname, "../environment/.env"),
|
path: dotenvPath,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue