feat(release): Setup automatic docker build
This commit is contained in:
parent
a3c1bae6db
commit
d5f5fe5f1a
8 changed files with 79 additions and 5 deletions
35
.forgejo/workflows/build-release-container.yaml
Normal file
35
.forgejo/workflows/build-release-container.yaml
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
name: build-container
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- release-*
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: node-20
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Run build
|
||||
run: npm run build
|
||||
|
||||
- name: Install Docker
|
||||
run: curl https://get.docker.com | sh
|
||||
- name: Setup Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Login to Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
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"
|
||||
4
examples/.env.example
Normal file
4
examples/.env.example
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
DISCORD_API_KEY=<YOURKEY>
|
||||
DISCORD_CLIENT_ID=<YOURCLIENTID>
|
||||
|
||||
DB_PATH=data/data.db
|
||||
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: neintonine/pnp-scheduler:release
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
env_file:
|
||||
- .env
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
"main": "main.ts",
|
||||
"scripts": {
|
||||
"build": "node ./build/build-cli.mjs",
|
||||
"build:docker": "sudo docker build .",
|
||||
"watch": "node ./build/watch.mjs",
|
||||
"deploy": "node ./dist/deploy.js",
|
||||
"start": "node ./dist/main.js",
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ export class Services {
|
|||
container.set<Logger>(logger, 'logger');
|
||||
|
||||
const database = new DatabaseConnection(env.database);
|
||||
database.connect()
|
||||
container.set<DatabaseConnection>(database);
|
||||
|
||||
const eventHandler = new EventHandler();
|
||||
|
|
|
|||
|
|
@ -3,12 +3,22 @@ import Sqlite3 from "better-sqlite3";
|
|||
import Database from "better-sqlite3";
|
||||
import {Container} from "../Container/Container";
|
||||
import {Logger} from "log4js";
|
||||
import path from "node:path";
|
||||
import * as fs from "node:fs";
|
||||
|
||||
export class DatabaseConnection {
|
||||
private database: Sqlite3.Database;
|
||||
|
||||
constructor(env: DatabaseEnvironment) {
|
||||
this.database = new Database(env.path, {
|
||||
constructor(private readonly env: DatabaseEnvironment) {
|
||||
}
|
||||
|
||||
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",
|
||||
})
|
||||
this.database.pragma('journal_mode = WAL');
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import dotenv from "dotenv";
|
||||
import path from "node:path";
|
||||
import * as fs from "node:fs";
|
||||
|
||||
type DiscordEnvironment = {
|
||||
token: string;
|
||||
guildId: string;
|
||||
clientId: string;
|
||||
}
|
||||
|
||||
|
|
@ -15,7 +15,6 @@ export class Environment {
|
|||
get discord(): DiscordEnvironment {
|
||||
return {
|
||||
token: process.env.DISCORD_API_KEY ?? '',
|
||||
guildId: process.env.DISCORD_GUILD_ID ?? '',
|
||||
clientId: process.env.DISCORD_CLIENT_ID ?? '',
|
||||
}
|
||||
}
|
||||
|
|
@ -27,8 +26,14 @@ export class Environment {
|
|||
}
|
||||
|
||||
public setup() {
|
||||
const dotenvPath = path.resolve(__dirname, "../environment/.env");
|
||||
|
||||
if (!fs.existsSync(dotenvPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
dotenv.config({
|
||||
path: path.resolve(__dirname, "../environment/.env"),
|
||||
path: dotenvPath,
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue