diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eeeee91 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +install.bat +LICENSE.md +Dockerfile diff --git a/.github/workflows/docker_workflow.yml b/.github/workflows/docker_workflow.yml new file mode 100644 index 0000000..f67871b --- /dev/null +++ b/.github/workflows/docker_workflow.yml @@ -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 }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8f2bfaa --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index 14e02dc..ed070a1 100644 --- a/README.md +++ b/README.md @@ -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 +``` \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..71d2c96 --- /dev/null +++ b/entrypoint.sh @@ -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