Commit 59874333 authored by Imran Hussain's avatar Imran Hussain
Browse files
parent 20f2a3c7
Pipeline #634 passed with stage
in 19 minutes and 48 seconds
# NodeJS Docker Example
# A sad Discord bot named Marvin
This repo is an example of how to create a Docker Image out of a NodeJS app.
A Discord bot for SUCS and maybe other servers.
You can literally just fork and rename the repo.
Relatively simple structure, index.js is the init, reads files in `events` dir
that coorospond to incoming events from Discord. Bot commands are handled by
messages.js which should look in the `commands` dir for the coorosponding
## What Images are Built?
`master` branch is latest and greatest, `tags` are for specific vertsions/releases.
By default this is what is built.
## How to dev?
* latest - Every time you push to master a image is built with the image tag being the git commit full hash. This same image is also tagged as `latest`
* tag - Every time you create a new git tag, a new image is built with that same tag.
You'll need your own testing server for now.
## Files in this repo
1. Close the repo
2. Get a bot token for a dev server
3. Create a file called .env and add the line `BOT_TOKEN=<your token here`
4. Run `npm run dev` and changes to files are tracked automagically
| File | Explanation |
| --- | --- |
| .dockerignore | List of files not to be copied into the docker image. |
| .gitignore | List of files to not be included in the git repo |
| .gitlab-ci.yml | Settings file for Gitlab CI that tells it what to do and how. In this case build and publish a docker image. |
| Dockerfile | File used by Docker (Google Kaniko in this case) to build a docker image. Change the initial NodeJS run file in here. |
| | What you are reading right now :) |
| package.json | Example NodeJS package.json file |
| npm-shrinkwrap.json | Example NodeJS npm-shrinkwrap.json file |
| index.js | Example NodeJS code file |
\ No newline at end of file
## How to contribute?
Fork the repo, create a branch per feature/bug, and submit a Merge Request.
\ No newline at end of file
module.exports = message => {
const member = message.mentions.members.first();
if (!member) {
return message.reply(
`Who are you trying to kick? You must mention a user.`
if (!member.kickable) {
return message.reply(`I can't kick this user. Sorry!`);
return member
.then(() => message.reply(`${member.user.tag} was kicked.`))
.catch(error => message.reply(`Sorry, an error occured.`));
module.exports = (client, member) => {
`Welcome on the server!`
\ No newline at end of file
const kick = require("../commands/kick");
module.exports = (client, message) => {
if (message.content.startsWith(".kick")) {
return kick(message);
if (message.content.startsWith(".e")) {
message.reply(`This is not MW!`);
\ No newline at end of file
module.exports = client => {
console.log(`Logged in as ${client.user.tag}!`);
\ No newline at end of file
console.log('Hello, world!');
const Discord = require("discord.js");
const fs = require("fs");
const client = new Discord.Client();
//main event handler, look in a folder clled "events" and when one comes in
//that matches use that file
fs.readdir("./events/", (err, files) => {
files.forEach(file => {
const eventHandler = require(`./events/${file}`);
const eventName = file.split(".")[0];
client.on(eventName, (...args) => eventHandler(client, ...args));
\ No newline at end of file
This diff is collapsed.
"name": "nodejs-docker-example",
"description": "Test NodeJS app for Docker example",
"version": "1.0.0",
"name": "Marvin",
"description": "A sad Discord Bot",
"version": "0.0.1",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"repository": {
"type": "git",
"url": ""
"url": ""
"keywords": [],
"author": "Imran Hussain <>",
"license": "ISC",
"bugs": {
"url": ""
"url": ""
"homepage": ""
"homepage": "",
"dependencies": {
"discord.js": "^11.5.1",
"dotenv": "^8.2.0"
"devDependencies": {
"nodemon": "^1.19.4"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment