[READ-ONLY] Mirror of https://github.com/maybeanerd/MagiBot. MagiBot - the community building discord bot that adds joinsounds to your voice channels! discord.gg/2Evcf4T
bot bots community discord gaming hacktoberfest sound
1

Configure Feed

Select the types of activity you want to include in your feed.

build: create Dockerfile and container setup

including pipelines to build the container

Sebastian Di Luzio (Jan 2, 2023, 10:26 PM +0100) 2fb4a64b ecd55fde

+138 -34
+5
.dockerignore
··· 1 + dist 2 + node_modules 3 + joinsounds 4 + .git 5 + .env
+6 -6
.github/workflows/nodejs.yml .github/workflows/linting.yml
··· 1 - name: Node CI 1 + name: Linting 2 2 3 3 on: 4 - pull_request: 5 - branches: 6 - - '**' 7 4 push: 8 5 branches: 9 6 - main 7 + pull_request: 8 + branches: 9 + - '**' 10 10 11 11 jobs: 12 - build: 12 + lint_and_typecheck: 13 13 runs-on: ubuntu-latest 14 14 15 15 strategy: ··· 29 29 - name: build 30 30 run: npm run build 31 31 - name: test 32 - run: npm run test --if-present 32 + run: npm run test --if-present
+18
.github/workflows/pr.yml
··· 1 + name: Pull request 2 + on: 3 + pull_request: 4 + branches: 5 + - '**' 6 + 7 + jobs: 8 + build_container: 9 + runs-on: ubuntu-latest 10 + 11 + steps: 12 + - name: Checkout 13 + uses: actions/checkout@v3 14 + - name: Build & Start containers 15 + run: docker-compose up -d --build 16 + - name: Stop containers 17 + if: always() 18 + run: docker-compose down
+42
.github/workflows/release.dev.yml
··· 1 + name: Release to dev 2 + 3 + on: 4 + push: 5 + branches: 6 + - main 7 + 8 + jobs: 9 + container: 10 + runs-on: ubuntu-latest 11 + environment: dev 12 + 13 + steps: 14 + - name: Checkout 15 + uses: actions/checkout@v3 16 + - name: See if ownerid is defined 17 + if: "${{ env.OWNERID != '' }}" 18 + run: echo "This command is executed if OWNERID secret IS NOT empty, and it is $OWNERID" 19 + env: 20 + OWNERID: ${{ secrets.OWNERID }} 21 + - name: Build & Start containers 22 + run: docker compose up -d --build 23 + env: 24 + TEST: test value to see 25 + TOKEN: ${{ secrets.TOKEN }} 26 + OWNERID: ${{ secrets.OWNERID }} 27 + PREFIX: ${{ secrets.PREFIX }} 28 + DATABASE_URL: ${{ secrets.DATABASE_URL }} 29 + STATCORD_TOKEN: ${{ secrets.STATCORD_TOKEN }} 30 + APP_ID: ${{ secrets.APP_ID }} 31 + WEBHOOK_ID_EX: ${{ secrets.WEBHOOK_ID_EX }} 32 + WEBHOOK_TOKEN_EX: ${{ secrets.WEBHOOK_TOKEN_EX }} 33 + WEBHOOK_ID_JOIN: ${{ secrets.WEBHOOK_ID_JOIN }} 34 + WEBHOOK_TOKEN_JOIN: ${{ secrets.WEBHOOK_TOKEN_JOIN }} 35 + WEBHOOK_ID_BUG: ${{ secrets.WEBHOOK_ID_BUG }} 36 + WEBHOOK_TOKEN_BUG: ${{ secrets.WEBHOOK_TOKEN_BUG }} 37 + WEBHOOK_ID_STARTUP: ${{ secrets.WEBHOOK_ID_STARTUP }} 38 + WEBHOOK_TOKEN_STARTUP: ${{ secrets.WEBHOOK_TOKEN_STARTUP }} 39 + # TODO deploy container 40 + - name: Stop containers 41 + if: always() 42 + run: docker-compose down
+19
.github/workflows/release.prod.yml
··· 1 + name: Release to production 2 + 3 + on: 4 + release: 5 + 6 + jobs: 7 + container: 8 + runs-on: ubuntu-latest 9 + environment: prod 10 + 11 + steps: 12 + - name: Checkout 13 + uses: actions/checkout@v3 14 + - name: Build & Start containers 15 + run: docker-compose up -d --build 16 + # TODO deploy container 17 + - name: Stop containers 18 + if: always() 19 + run: docker-compose down
+19
Dockerfile
··· 1 + FROM node:16 2 + WORKDIR /app 3 + 4 + # Install FFMPEG 5 + RUN apt-get -y update 6 + RUN apt-get -y upgrade 7 + RUN apt-get install -y ffmpeg 8 + 9 + # Intall dependencies 10 + COPY ["package.json", "package-lock.json*", "./"] 11 + RUN npm ci 12 + 13 + # Build 14 + COPY . . 15 + RUN npm run build 16 + # TODO mount external storage to store joinsounds 17 + 18 + # Start service 19 + CMD ["npm", "run", "start"]
+26
docker-compose.yml
··· 1 + version: "3.9" 2 + services: 3 + main: 4 + build: . 5 + volumes: 6 + - main:/app 7 + environment: 8 + - TOKEN=${TOKEN} 9 + # TODO remove the need for this 10 + - PREFIX=${PREFIX} 11 + - OWNERID=${OWNERID} 12 + - DATABASE_URL=${DATABASE_URL} 13 + - STATCORD_TOKEN=${STATCORD_TOKEN} 14 + - APP_ID=${APP_ID} 15 + 16 + # discord webhook tokens 17 + - WEBHOOK_ID_EX=${WEBHOOK_ID_EX} 18 + - WEBHOOK_TOKEN_EX=${WEBHOOK_TOKEN_EX} 19 + - WEBHOOK_ID_JOIN=${WEBHOOK_ID_JOIN} 20 + - WEBHOOK_TOKEN_JOIN=${WEBHOOK_TOKEN_JOIN} 21 + - WEBHOOK_ID_BUG=${WEBHOOK_ID_BUG} 22 + - WEBHOOK_TOKEN_BUG=${WEBHOOK_TOKEN_BUG} 23 + - WEBHOOK_ID_STARTUP=${WEBHOOK_ID_STARTUP} 24 + - WEBHOOK_TOKEN_STARTUP=${WEBHOOK_TOKEN_STARTUP} 25 + volumes: 26 + main:
-24
package-lock.json
··· 21 21 "fast-folder-size": "1.7.1", 22 22 "ffmpeg-static": "5.1.0", 23 23 "ffprobe": "1.1.2", 24 - "ffprobe-static": "3.1.0", 25 24 "forever": "4.0.3", 26 25 "libsodium-wrappers": "^0.7.10", 27 26 "mongoose": "6.8.2", ··· 33 32 "devDependencies": { 34 33 "@types/centra": "2.2.0", 35 34 "@types/ffprobe": "1.1.3", 36 - "@types/ffprobe-static": "2.0.1", 37 35 "@types/node": "16.18.11", 38 36 "@typescript-eslint/eslint-plugin": "5.47.1", 39 37 "@typescript-eslint/parser": "5.47.1", ··· 1350 1348 "version": "1.1.3", 1351 1349 "resolved": "https://registry.npmjs.org/@types/ffprobe/-/ffprobe-1.1.3.tgz", 1352 1350 "integrity": "sha512-kZMDb2ThiDRRt8i/Z+oXUSxcWbclvGj9no9piODl/Y1Ws3opmEIe+/+l5Ige/31MD61qwLGLey/PanGmXJor1w==", 1353 - "dev": true 1354 - }, 1355 - "node_modules/@types/ffprobe-static": { 1356 - "version": "2.0.1", 1357 - "resolved": "https://registry.npmjs.org/@types/ffprobe-static/-/ffprobe-static-2.0.1.tgz", 1358 - "integrity": "sha512-V5CrKUfms0lBGSXliKmKzSFFZWgJusQks1YfjRI/+2dXFF+aK7qBAarCe/ryYHQI44jYQX7xtlgH0fCuJepuGQ==", 1359 1351 "dev": true 1360 1352 }, 1361 1353 "node_modules/@types/json-schema": { ··· 3662 3654 "JSONStream": "^1.3.5" 3663 3655 } 3664 3656 }, 3665 - "node_modules/ffprobe-static": { 3666 - "version": "3.1.0", 3667 - "resolved": "https://registry.npmjs.org/ffprobe-static/-/ffprobe-static-3.1.0.tgz", 3668 - "integrity": "sha512-Dvpa9uhVMOYivhHKWLGDoa512J751qN1WZAIO+Xw4L/mrUSPxS4DApzSUDbCFE/LUq2+xYnznEahTd63AqBSpA==" 3669 - }, 3670 3657 "node_modules/file-entry-cache": { 3671 3658 "version": "6.0.1", 3672 3659 "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", ··· 8608 8595 "integrity": "sha512-kZMDb2ThiDRRt8i/Z+oXUSxcWbclvGj9no9piODl/Y1Ws3opmEIe+/+l5Ige/31MD61qwLGLey/PanGmXJor1w==", 8609 8596 "dev": true 8610 8597 }, 8611 - "@types/ffprobe-static": { 8612 - "version": "2.0.1", 8613 - "resolved": "https://registry.npmjs.org/@types/ffprobe-static/-/ffprobe-static-2.0.1.tgz", 8614 - "integrity": "sha512-V5CrKUfms0lBGSXliKmKzSFFZWgJusQks1YfjRI/+2dXFF+aK7qBAarCe/ryYHQI44jYQX7xtlgH0fCuJepuGQ==", 8615 - "dev": true 8616 - }, 8617 8598 "@types/json-schema": { 8618 8599 "version": "7.0.11", 8619 8600 "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", ··· 10390 10371 "deferential": "^1.0.0", 10391 10372 "JSONStream": "^1.3.5" 10392 10373 } 10393 - }, 10394 - "ffprobe-static": { 10395 - "version": "3.1.0", 10396 - "resolved": "https://registry.npmjs.org/ffprobe-static/-/ffprobe-static-3.1.0.tgz", 10397 - "integrity": "sha512-Dvpa9uhVMOYivhHKWLGDoa512J751qN1WZAIO+Xw4L/mrUSPxS4DApzSUDbCFE/LUq2+xYnznEahTd63AqBSpA==" 10398 10374 }, 10399 10375 "file-entry-cache": { 10400 10376 "version": "6.0.1",
-2
package.json
··· 23 23 "fast-folder-size": "1.7.1", 24 24 "ffmpeg-static": "5.1.0", 25 25 "ffprobe": "1.1.2", 26 - "ffprobe-static": "3.1.0", 27 26 "forever": "4.0.3", 28 27 "libsodium-wrappers": "^0.7.10", 29 28 "mongoose": "6.8.2", ··· 40 39 "devDependencies": { 41 40 "@types/centra": "2.2.0", 42 41 "@types/ffprobe": "1.1.3", 43 - "@types/ffprobe-static": "2.0.1", 44 42 "@types/node": "16.18.11", 45 43 "@typescript-eslint/eslint-plugin": "5.47.1", 46 44 "@typescript-eslint/parser": "5.47.1",
+3 -2
src/commands/joinsound/management.ts
··· 1 1 import ffprobe from 'ffprobe'; 2 - import { path as ffProbePath } from 'ffprobe-static'; 3 2 import { CommandInteraction, MessageAttachment, User } from 'discord.js'; 4 3 import { APIEmbed, APIEmbedField } from 'discord-api-types/v10'; 5 4 import { ··· 135 134 return setDefaultGuildJoinsound(guildId, undefined, true); 136 135 } 137 136 137 + const defaultFFProbeLocation = '/usr/bin/ffprobe'; 138 + 138 139 export async function validateAndSaveJoinsound( 139 140 attachment: MessageAttachment, 140 141 interaction: CommandInteraction, ··· 162 163 const soundUrl = attachment.url; 163 164 164 165 const sound = await ffprobe(soundUrl, { 165 - path: ffProbePath, 166 + path: defaultFFProbeLocation, 166 167 }).catch((error) => { 167 168 console.error(error); 168 169 });