Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Docker preps #52

Merged
merged 1 commit into from
Oct 12, 2020
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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
},
overrides: [
{
files: ['lang/*.js'],
files: ['app/lang/*.js'],
rules: {
'require-jsdoc': 'off',
},
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/build-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Build Workflow
on:
push:
branches:
- main
jobs:
job_one:
name: Build and push docker images
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build docker-image
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
docker build -f ./docker/spooky-node/DockerfileProd --build-arg NODE_VERSION=12.18.2 -t spookybot/spookybot:latest -t spookybot/spookybot:${{github.run_number}} .
docker push spookybot/spookybot:${{github.run_number}}
docker push spookybot/spookybot:latest
docker logout


24 changes: 24 additions & 0 deletions .github/workflows/deploy-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Deployment Workflow
on:
workflow_dispatch:
inputs:
tags:
description: 'Tag'
jobs:
deploy_prod_bot:
runs-on: ubuntu-latest
steps:
- uses: appleboy/ssh-action@master
name: deploy to prod
with:
host: ${{ secrets.SSH_IP }}
port: ${{ secrets.SSH_PORT }}
username: spookybot
key: ${{ secrets.SSH_KEY }}
script: |
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
docker pull spookybot/spookybot:latest
docker-compose -f /home/spookybot/docker-compose.yml down -v
docker-compose -f /home/spookybot/docker-compose.yml up -d
docker logout

6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ jspm_packages/

# Optional eslint cache
.eslintcache
.eslintrc.js

# Yarn Integrity file
.yarn-integrity

# config file
config.json

app/config/config.json
# IDE
.idea
*.iml


14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DOCKERCOMPOSE_DEV=-f docker-compose.dev.yml


.PHONY: build_dev_image
build_dev_image:
docker build -f ./docker/spooky-node/DockerfileDev -t spookybot:dev .

.PHONY: startup_dev
startup_dev:
docker-compose ${DOCKERCOMPOSE_DEV} up -d

.PHONY: stop_dev
stop_dev:
docker-compose ${DOCKERCOMPOSE_DEV} down -v
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ You can see that the `emoji` element is an emoji, but you can also use a custom
## 💻 Testing locally
1. Create a bot [on the Discord developer portal](https://discord.com/developers/applications),
2. Create a webhook on your own discord server [by folloing this tutorial](https://docs.gitlab.com/ee/user/project/integrations/discord_notifications.html),
3. Copy the `config.example.json` from the project to `config.json` and fill in the gaps with the information from the bot and the webhook. The first token is on the bot page accessed from the side of the Discord Developer Portal, and the webook information is found on the page when you navigate to the webhook url,
3. Copy the `config.example.json` from the project to `app/config/config.json` and fill in the gaps with the information from the bot and the webhook. The first token is on the bot page accessed from the side of the Discord Developer Portal, and the webook information is found on the page when you navigate to the webhook url,
4. Invite your dev bot to your server by [following this url](https://discord.com/oauth2/authorize?client_id=761568927188123669&scope=bot&permissions=1141124160), replacing the client id with your bot's client id (found on it's general information page), and the permissions with the Permission Integer created in the Developer Portal as you select permissions for your bot,
5. Once these steps are setup, simply run `yarn install` and `npm run dev` from the terminal in the root directory of the repo,
5. Once these steps are setup, simply run `make startup_dev` from the terminal in the root directory of the repo,
5.1 If you want to install node modules you could just add it into your local package.json and run the `make build_dev_image` after that you need to recreate the container.
6. Test the bot is connected by running `<your-prefix>help` to get a list of commands, and then initialize the DB by running `<your-prefix>emitgc`. It should then respond with "Join <your-server> with <#> users,
7. Test that the bot reacts to comments by typing one of the words in `lang/<your-lang>.js`. The bot should respond with an emoji!

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { MessageEmbed } = require('discord.js')
const { prefix, colors } = require('../../config.json')
const { prefix, colors } = require('../../config/config.json')

const { readdirSync } = require('fs')
const { resolve } = require('path')
Expand Down
4 changes: 2 additions & 2 deletions commands/Info/help.js → app/commands/Info/help.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { MessageEmbed } = require('discord.js')
const { prefix, colors } = require('../../config.json')
const { version } = require('../../package.json')
const { prefix, colors } = require('../../config/config.json')
const { version } = require('../../../package.json')

module.exports = {
config: {
Expand Down
2 changes: 1 addition & 1 deletion commands/Info/invite.js → app/commands/Info/invite.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { MessageEmbed } = require('discord.js')
const { prefix, colors } = require('../../config.json')
const { prefix, colors } = require('../../config/config.json')

module.exports = {
config: {
Expand Down
2 changes: 1 addition & 1 deletion commands/Info/ping.js → app/commands/Info/ping.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { MessageEmbed } = require('discord.js')
const { prefix, colors } = require('../../config.json')
const { prefix, colors } = require('../../config/config.json')

module.exports = {
config: {
Expand Down
2 changes: 1 addition & 1 deletion commands/Info/support.js → app/commands/Info/support.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { MessageEmbed } = require('discord.js')
const { prefix, colors } = require('../../config.json')
const { prefix, colors } = require('../../config/config.json')

module.exports = {
config: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { prefix } = require('../../config.json')
const { prefix } = require('../../config/config.json')
const { readdirSync } = require('fs')
const { resolve } = require('path')

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { treat, trick, createTrickOrTreat, getTrickOrTreat } = require('../../models/trickortreats')
const { prefix } = require('../../config.json')
const { readdirSync } = require('fs')
const { resolve } = require('path')
const { prefix } = require('../../config/config.json')


const isToday = (someDate) => {
const today = new Date()
Expand Down
Empty file added app/config/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion core.js → app/core.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Client, Collection, WebhookClient } = require('discord.js')

const { token, webhook } = require('./config.json')
const { token, webhook } = require('./config/config.json')

const bot = new Client()

Expand Down
Empty file added app/db/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion db/servers.json → app/db/servers.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"servers": []
}
}
10 changes: 10 additions & 0 deletions app/db/trickortreats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"trickortreats": [
{
"userId": "306856370454396928",
"tricks": 0,
"treats": 0,
"lastPlayed": "2020-10-06T22:55:33.107Z"
}
]
}
2 changes: 1 addition & 1 deletion events/guildCreate.js → app/events/guildCreate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { MessageEmbed } = require('discord.js')
const { colors } = require('../config.json')
const { colors } = require('../config/config.json')

const { createGuild } = require('../models/servers')

Expand Down
2 changes: 1 addition & 1 deletion events/guildDelete.js → app/events/guildDelete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { MessageEmbed } = require('discord.js')
const { colors } = require('../config.json')
const { colors } = require('../config/config.json')

const { deleteGuild } = require('../models/servers')

Expand Down
2 changes: 1 addition & 1 deletion events/message.js → app/events/message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { MessageEmbed } = require('discord.js')
const { prefix, colors } = require('../config.json')
const { prefix, colors } = require('../config/config.json')

const reactMessage = require('../utils/reactMessage')

Expand Down
2 changes: 1 addition & 1 deletion events/ready.js → app/events/ready.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { prefix } = require('../config.json')
const { prefix } = require('../config/config.json')

let statusInterval = 0
if (process.env.NODE_ENV === 'dev') {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion models/servers.js → app/models/servers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const { resolve } = require('path')

const adapter = new FileSync('db/servers.json')
const adapter = new FileSync(resolve(__dirname, `../db/servers.json`))
const db = low(adapter)

// Set some defaults (required if your JSON file is empty)
Expand Down
4 changes: 2 additions & 2 deletions models/trickortreats.js → app/models/trickortreats.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')

const adapter = new FileSync('db/trickortreats.json')
const { resolve } = require('path')
const adapter = new FileSync(resolve(__dirname, `../db/trickortreats.json`))
const db = low(adapter)

// Set some defaults (required if your JSON file is empty)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions db/trickortreats.json

This file was deleted.

13 changes: 13 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.6'

services:
spooky-bot:
image: spookybot/spookybot:latest
build:
context: .
dockerfile: docker/spooky-node/DockerfileProd
args:
- NODE_VERSION=12.18.2
volumes:
- ./app:/spooky/app/:rw
- ./package.json:/spooky/package.json
16 changes: 16 additions & 0 deletions docker/spooky-node/DockerfileDev
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG NODE_VERSION

FROM node:${NODE_VERSION} AS build

COPY . /spooky

WORKDIR /spooky
RUN npm cache clean --force
RUN rm -rf node_modules
RUN npm install

FROM node:${NODE_VERSION}
WORKDIR /spooky
COPY --from=build /spooky /spooky

ENTRYPOINT ["npm", "run", "dev"]
14 changes: 14 additions & 0 deletions docker/spooky-node/DockerfileProd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG NODE_VERSION

FROM node:${NODE_VERSION}

COPY . /spooky

WORKDIR /spooky
RUN npm cache clean --force
RUN rm -rf node_modules
RUN npm install --production

RUN rm -rf app/config
RUN rm -rf app/db
ENTRYPOINT ["npm", "run", "start"]
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "spookybot",
"version": "1.0.0",
"description": "A spooky Discord bot",
"main": "core.js",
"main": "app/core.js",
"repository": "[email protected]:LucasCtrl/spookyBot.git",
"author": "LucasCtrl <[email protected]>",
"license": "MIT",
Expand All @@ -21,7 +21,7 @@
"prettier": "^2.1.2"
},
"scripts": {
"dev": "nodemon --inspect core.js",
"start": "node core.js"
"dev": "nodemon --inspect ./app/core.js",
"start": "node app/core.js"
}
}
Loading