Skip to content

Docker image creation #133

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
install.bat
LICENSE.md
Dockerfile
41 changes: 41 additions & 0 deletions .github/workflows/docker_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Create and publish image

on:
push:
branches: ['master']

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@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.DEPLOY_TOKEN }}

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

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:gallium-bullseye-slim

WORKDIR /bot
RUN apt update && apt install -y jq
COPY . /bot
RUN npm install
CMD export $(env | grep SD_ | cut -d= -f1 | xargs); bash entrypoint.sh
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,39 @@ Once you complete all of this, you will be able to run the bot by executing run.
`Connected to game. Connected to 1 Discord Servers.`

To set the channel for your server's chat, open Discord and type `7d!setchannel #yourchannel` in your server. If the setchannel command doesn't work, try [setting it manually](https://github.com/LakeYS/Dishorde/wiki/Setting-up-the-channel-manually). Once complete, the bot should be all set!

# Run the bot in docker
If you choose to run the bot in docker you can

As a docker-compose

```
services:
dishorde:
image: ghcr.io/LakeYS/dishorde:latest
container_name: dishorde
environment:
SD_IP: 7days_ip_address
SD_PASSWORD: your_7days_password
SD_TOKEN: Discord_token
SD_CHANNEL: discord_channel
SD_PORT: 8081
networks:
- 7days
restart: unless-stopped

networks:
7days: {}
```

As a standlaone docker image deployment

```
docker run -d \
-e SD_IP=7days_ip_address \
-e SD_PASSWORD=your_7days_password \
-e SD_TOKEN=Discord_token \
-e SD_CHANNEL=discord_channel \
-e SD_PORT=8081 \
ghcr.io/LakeYS/dishorde:latest
```
32 changes: 32 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

if [[ ! -z $SD_IP ]]; then
jq --arg IP $SD_IP -r '.ip |= $IP' /bot/config.json > /bot/config_tmp.json
mv /bot/config_tmp.json /bot/config.json
fi

if [[ ! -z $SD_PASSWORD ]]; then
jq --arg PASSWORD $SD_PASSWORD -r '.password |= $PASSWORD' /bot/config.json > /bot/config_tmp.json
mv /bot/config_tmp.json /bot/config.json
fi

if [[ ! -z $SD_TOKEN ]]; then
jq --arg TOKEN $SD_TOKEN -r '.token |= $TOKEN' /bot/config.json > /bot/config_tmp.json
mv /bot/config_tmp.json /bot/config.json
fi

if [[ ! -z $SD_CHANNEL ]]; then
jq --arg CHANNEL $SD_CHANNEL -r '.channel |= $CHANNEL' /bot/config.json > /bot/config_tmp.json
mv /bot/config_tmp.json /bot/config.json
fi

if [[ ! -z $SD_PORT ]]; then
jq --arg PORT $SD_PORT -r '.port |= $PORT' /bot/config.json > /bot/config_tmp.json
mv /bot/config_tmp.json /bot/config.json
fi

# Auto restart
until node index.js; do
echo "Application closed with exit code $?. Restarting in 5s, press Ctrl+C to cancel." >&2
sleep 5
done