Skip to content
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

Dockerize #246

Merged
merged 7 commits into from
Aug 29, 2023
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
32 changes: 32 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# temporary stuff, this will be handled in the db eventually
TEMP_GUILD_ID=
TEMP_CHANNEL_AUTOMATION_CHANNEL_ID=
TEMP_LOGGING_CHANNEL_ID=
TEMP_JOINING_CHANNEL_ID=
TEMP_LEAVING_CHANNEL_ID=
TEMP_DELETION_LOGGING_CHANNEL_ID=

# Mongo database information
MONGODB_CONNECTION_URI=mongodb://localhost
MONGODB_DATABASE=test

# Discord bot options
DISCORD_TOKEN=discord bot token goes here
DISCORD_PREFIX=.
DISCORD_CLIENT_ID=discord app client ID goes here
DISCORD_CLIENT_SECRET=discord app client secret goes here
DISCORD_REDIRECT_URI=discord redirect URI goes here

# Reddit API authorization info
REDDIT_CLIENT_ID=reddit app client ID goes here
REDDIT_CLIENT_SECRET=reddit app client secret goes here
REDDIT_USER_AGENT=put in a user agent that includes your /u/
REDDIT_REDIRECT_URI=reddit redirect URI goes here

# Web server config
PORT=4567
HOST=http://localhost:4567
SESSION_SECRET=something sufficiently secret

# Third party APIs for command functionality
FREECURRENCYAPI_KEY=
44 changes: 44 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build and publish Docker image

on:
push:
branches: ['main']

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_COMMIT_HASH=${{ github.sha }}
GIT_REPO_URL=${{ github.repostitoryUrl }}
62 changes: 0 additions & 62 deletions .github/workflows/deploy.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules

# Secrets
config.*
.env

# Migration tracking
.migrate
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://nodejs.org/en/docs/guides/nodejs-docker-webapp
FROM node:18-alpine
WORKDIR /usr/src/app

# copy package.json/package-lock.json and install dependencies
COPY package*.json ./
RUN npm ci --omit=dev

# copy everything else
COPY . .

# pull in git references from build args
ARG GIT_COMMIT_HASH
ENV GIT_COMMIT_HASH=$GIT_COMMIT_HASH
ARG GIT_REPO_URI
ENV GIT_REPO_URI=$GIT_REPO_URI

EXPOSE 8080
USER node
CMD ["sh", "-c", "PORT=8080 NODE_ENV=production npx ts-node --transpile-only src/index.js"]
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# misato [![deploy status](https://img.shields.io/github/deployments/r-anime/discord-mod-bot/production?label=deploy)](https://github.com/r-anime/discord-mod-bot/deployments/activity_log?environment=production)
# misato

It's not much, but it's ours.

Expand All @@ -11,8 +11,8 @@ You'll want [Node](https://nodejs.org/en/download/) 12+ and a [MongoDB](https://
```bash
# Install dependencies
npm install
# Create your config file from the sample and fill it in
cp sample.config.js config.js && $EDITOR config.js
# Create your environment file from the sample and fill it in
cp .env.sample .env && $EDITOR .env
# Migrate the database
npx migrate up
```
Expand All @@ -26,6 +26,9 @@ npm install
npm run start
```

## Usage with Docker


## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).
Expand Down
2 changes: 0 additions & 2 deletions logger.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Describes custom log levels for the `another-logger` package.
import config from './config';

module.exports = {
levels: {
erisError: {style: 'red', text: 'error (eris)'},
Expand Down
11 changes: 6 additions & 5 deletions migrations/1587086572450-create-collection-reminders.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const {MongoClient} = require('mongodb');
const config = require('../config');

const {MONGODB_CONNECTION_URI, MONGODB_DATABASE} = process.env;

module.exports.up = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.createCollection('reminders', {
validator: {
Expand Down Expand Up @@ -34,9 +35,9 @@ module.exports.up = async () => {
};

module.exports.down = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.dropCollection('reminders');
};
10 changes: 5 additions & 5 deletions migrations/1588376720668-create-collection-discordUsers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const {MongoClient} = require('mongodb');
const config = require('../config');
const {MONGODB_CONNECTION_URI, MONGODB_DATABASE} = process.env;

module.exports.up = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.createCollection('redditAccounts', {
validator: {
Expand All @@ -25,9 +25,9 @@ module.exports.up = async () => {
};

module.exports.down = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.dropCollection('redditAccounts');
};
10 changes: 5 additions & 5 deletions migrations/1592636841669-create-collection-messageFilters.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const {MongoClient} = require('mongodb');
const config = require('../config');
const {MONGODB_CONNECTION_URI, MONGODB_DATABASE} = process.env;

module.exports.up = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.createCollection('messageFilters', {
validator: {
Expand All @@ -25,9 +25,9 @@ module.exports.up = async () => {
};

module.exports.down = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.dropCollection('messageFilters');
};
10 changes: 5 additions & 5 deletions migrations/1596302630862-add-guildid-to-redditaccounts.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const {MongoClient} = require('mongodb');
const config = require('../config');
const {MONGODB_CONNECTION_URI, MONGODB_DATABASE} = process.env;

module.exports.up = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.command({
collMod: 'redditAccounts',
Expand All @@ -29,9 +29,9 @@ module.exports.up = async () => {
};

module.exports.down = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.command({
collMod: 'redditAccounts',
Expand Down
10 changes: 5 additions & 5 deletions migrations/1596492986396-add-redditnames-unique-index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const {MongoClient} = require('mongodb');
const config = require('../config');
const {MONGODB_CONNECTION_URI, MONGODB_DATABASE} = process.env;

module.exports.up = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.collection('redditAccounts').createIndex({userID: 1, guildID: 1, redditName: 1}, {unique: true});
};

module.exports.down = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.collection('redditAccounts').dropIndex({userID: 1, guildID: 1, redditName: 1}, {unique: true});
};
10 changes: 5 additions & 5 deletions migrations/1596502200514-create-collection-bans.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const {MongoClient} = require('mongodb');
const config = require('../config');
const {MONGODB_CONNECTION_URI, MONGODB_DATABASE} = process.env;

module.exports.up = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.createCollection('bans', {
validator: {
Expand Down Expand Up @@ -37,9 +37,9 @@ module.exports.up = async () => {
};

module.exports.down = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.dropCollection('bans');
};
10 changes: 5 additions & 5 deletions migrations/1596507742549-create-collection-kicks.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const {MongoClient} = require('mongodb');
const config = require('../config');
const {MONGODB_CONNECTION_URI, MONGODB_DATABASE} = process.env;

module.exports.up = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.createCollection('kicks', {
validator: {
Expand Down Expand Up @@ -34,9 +34,9 @@ module.exports.up = async () => {
};

module.exports.down = async () => {
const mongoClient = new MongoClient(config.mongodb.url, {useUnifiedTopology: true});
const mongoClient = new MongoClient(MONGODB_CONNECTION_URI, {useUnifiedTopology: true});
await mongoClient.connect();
const db = mongoClient.db(config.mongodb.databaseName);
const db = mongoClient.db(MONGODB_DATABASE);

await db.dropCollection('kicks');
};
Loading