Support a basic image on Docker Hub (#498)

* Revert "Revert "Merge branch 'docker-test'""

This reverts commit 2b4bcb1136.

* Use node 12 for docker image

* More thoroughly limit deploy to master pushes

* Use discordirc/discord-irc repo for Docker

* Tag git commit image for Docker hub

* Add .dockerignore
master
Edward Jones 2019-12-14 15:36:36 -03:00 committed by GitHub
parent 5d31e2d16b
commit 11a5347006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 82 additions and 0 deletions

20
.dockerignore Normal file
View File

@ -0,0 +1,20 @@
.git
# Coverage directory used by tools like istanbul
coverage
.nyc_output
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules
# Environment variables and configuration
.env
.environment
config.json
# Build
dist/

View File

@ -6,3 +6,17 @@ node_js:
- '10'
- '12'
- '13'
jobs:
include:
- stage: deploy
if: branch = master AND type = push
node_js: '12'
services:
- docker
script: skip
after_success: echo Skipping coverage.
deploy:
provider: script
script: bash docker-deploy.sh
on:
branch: master

15
Dockerfile Normal file
View File

@ -0,0 +1,15 @@
FROM node:12-alpine
ENV LIBRARY_PATH=/lib:/usr/lib
RUN mkdir /bot
COPY . /bot
WORKDIR /bot
RUN apk add --update tini && \
npm install && \
npm run build && \
mkdir /config
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["npm", "start", "--", "--config", "/config/config.json"]

View File

@ -38,6 +38,24 @@ import config from './config.json';
discordIRC(config);
```
## Docker
As an alternative to running discord-irc directly on your machine, we provide a [Docker container image](https://hub.docker.com/r/discordirc/discord-irc).
After creating a configuration file, you can fetch the image from Docker Hub and run it with the following command:
```bash
docker run -v /path/to/config:/config/config.json discordirc/discord-irc
```
If you've checked out the repository already, you can build the Docker image locally and run that instead:
```bash
docker build -t discord-irc .
docker run -v /path/to/config:/config/config.json discord-irc
```
Note that the path to the config file on the host (`/path/to/config`) _must_ be a valid absolute path to a config file.
Otherwise, you may get the error "illegal operation on a directory".
## Configuration
First you need to create a Discord bot user, which you can do by following the instructions [here](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token).

15
docker-deploy.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
set -e
echo "Connecting to docker hub"
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
REPO=discordirc/discord-irc
echo "Building..."
docker build -t $REPO:latest -t $REPO:$TRAVIS_COMMIT .
echo "Pushing image to Docker Hub..."
docker push $REPO:latest
docker push $REPO:$TRAVIS_COMMIT