diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..09d0ce447 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git +.github +.idea +.eslintrc.json +.gitignore +config.json +LICENSE +*.md diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml new file mode 100644 index 000000000..fa1ed81cf --- /dev/null +++ b/.github/workflows/container.yml @@ -0,0 +1,42 @@ +name: Build and push Docker image + +on: + push: + branches: + - master + release: + types: + - published + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + 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 000000000..48e84955b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:18-alpine + +ARG COMMIT_HASH + +# Set up files +WORKDIR /app +COPY . . + +# Install dependencies +ENV NODE_ENV=production +RUN npm ci + +# Environment +ENV MODBOT_COMMIT_HASH=$COMMIT_HASH +ENV MODBOT_USE_ENV=1 +CMD ["npm", "start"] \ No newline at end of file diff --git a/README.md b/README.md index 7bb27074c..038391590 100644 --- a/README.md +++ b/README.md @@ -48,17 +48,28 @@ If you think you found a bug in ModBot then please create an [issue](https://git For security issues please refer to the [SECURITY.md](./SECURITY.md). ### Self Hosting -Requirements: [Node.js](https://nodejs.org/en/download/) (v16.9.0+), a [MySQL](https://dev.mysql.com/downloads/mysql/) database -1. Download the code and run `npm install` -2. Create a [Discord application](https://discord.com/developers/applications/). - You also have to enable the SERVER MEMBERS intent. +If you want to host the bot yourself you can use our pre-built docker image or install it directly. +In both cases you will need a [MySQL](https://dev.mysql.com/downloads/mysql/) database and a +[Discord application](https://discord.com/developers/applications/): + +1. Create a [Discord application](https://discord.com/developers/applications/) and enable the SERVER MEMBERS intent. The bot needs this to reassign the muted role when a muted user joins your server -3. Add a bot to the application and copy the auth token -4. (optional) Create an API key in the [Google Cloud Console](https://console.cloud.google.com/) for the YouTube Data API v3 -5. Configure the bot (see [CONFIGURATION.md](./CONFIGURATION.md)) -6. Start the index.js file -7. To invite the bot to your server replace `ID` with the client ID of your application +2. Add a bot to the application and copy the auth token +3. Configure the bot (see [CONFIGURATION.md](./CONFIGURATION.md)) +4. To invite the bot to your server replace `ID` with the client ID of your application https://discord.com/oauth2/authorize?client_id=ID&scope=bot%20applications.commands&permissions=1099780074518 and open the link +5. Follow the instructions for the installation method you want to use + +#### Docker +Requirements: [Docker](https://docs.docker.com/get-docker/) +```bash +docker run -e MODBOT_AUTH_TOKEN="" -e MODBOT_DATABASE_HOST="" -e MODBOT_DATABASE_PASSWORD="" ghcr.io/aternosorg/modbot +``` + +#### Direct Installation +Requirements: [Node.js](https://nodejs.org/en/download/) (v16.9.0+), a [MySQL](https://dev.mysql.com/downloads/mysql/) database +1. Download the code and run `npm ci` +2. Run `npm start` to start the bot ### Contributing If you want to contribute you need to [fork](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) diff --git a/src/commands/bot/InfoCommand.js b/src/commands/bot/InfoCommand.js index cc3cdcdda..a9630bd3f 100644 --- a/src/commands/bot/InfoCommand.js +++ b/src/commands/bot/InfoCommand.js @@ -44,6 +44,10 @@ async function getPackageVersion() { export const COMMIT = await getGitCommit(); async function getGitCommit() { + if (process.env.MODBOT_COMMIT_HASH) { + return process.env.MODBOT_COMMIT_HASH; + } + try { return (await promisify(exec)('git rev-parse --short HEAD'))?.stdout?.replaceAll?.('\n', ''); } catch {