Skip to content

Commit

Permalink
Merge pull request #25 from AlexInCube/docker-refactoring
Browse files Browse the repository at this point in the history
2.4.2
  • Loading branch information
AlexInCube authored Apr 9, 2024
2 parents 5fe56b2 + 7ebb9d4 commit 74a3e4b
Show file tree
Hide file tree
Showing 12 changed files with 584 additions and 410 deletions.
7 changes: 6 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
node_modules
package-lock.json
.git
*Dockerfile*
*docker-compose*
.env*
runInDocker.*
yt-cookies.json
44 changes: 44 additions & 0 deletions .github/workflows/publish-docker-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish Docker image

on:
push:
branches: ['master']
pull_request:
branches: ['master']

env:
IMAGE_TAG: alexincube/aicotest

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract project version from package.json
id: package-version
uses: martinbeentjes/[email protected]

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.IMAGE_TAG }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ env.IMAGE_TAG }}:${{ steps.package-version.outputs.current-version }} , ${{ env.IMAGE_TAG }}:latest
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
build
data
/downloads/
/yt-cookies.json
27 changes: 16 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# syntax=docker/dockerfile:1
FROM bitnami/node:18.16.0
RUN apt update
RUN apt install git
RUN apt install -y ffmpeg
FROM node:20-alpine as base
RUN apk update && apk upgrade && apk add ffmpeg

FROM base as build
RUN apk add python3 && apk add build-base && apk add make
RUN npm i -g pnpm@latest
RUN mkdir -p /bot
WORKDIR /bot
RUN git clone https://github.com/AlexInCube/AlCoTest .
RUN pnpm install
WORKDIR /botbuild
COPY . .
RUN pnpm install --frozen-lockfile
RUN pnpm run build
COPY .env.production /bot
COPY yt-cookies.json /bot
CMD ["pnpm", "run", "production"]
RUN pnpm prune --prod

FROM base as prod
WORKDIR /bot
COPY --from=build /botbuild/build ./build
COPY --from=build /botbuild/node_modules ./node_modules
COPY --from=build /botbuild/package.json .
CMD ["npm", "run", "production"]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Cool audiobot for Discord created by <a href="https://vk.com/alexincube"><b>@Ale
- Localization (English and Russian are currently supported)

## 🎛️ Requirements
- Node.js 18 or higher
- Node.js 20 or higher
- MongoDB 6.0 or higher
- ffmpeg latest

Expand Down Expand Up @@ -72,7 +72,7 @@ npm run production
```

### 🐋 Run in Docker
- Copy docker-compose.yml, Dockerfile, runInDocker.bat (for Windows) or runInDocker.sh (for Linux) in empty folder
- Copy docker-compose.yml, Dockerfile in empty folder
- Follow the "Configure .env" section and put .env.production in folder with Dockerfile etc.
- Follow the "YouTube Cookie" section and put yt-cookies.json in the folder with Dockerfile etc.
- Run "runInDocker" file
- Run command ```docker-compose up --detach --force-recreate``` in folder with files
27 changes: 25 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,39 @@ services:
container_name: mongo
image: bitnami/mongodb:latest
restart: always
env_file:
- ./.env.production
- ./.env.development
volumes:
- ./data:/data/db
ports:
- '27018:27017'
bot:
container_name: bot
image: bot
restart: always
image: alexincube/aicotest:latest
deploy:
restart_policy:
condition: on-failure
delay: 15s
max_attempts: 3
window: 120s
#command: sleep infinity
build: .
env_file:
- ./.env.production
- ./.env.development
volumes:
- type: bind
source: ./yt-cookies.json
target: /bot/yt-cookies.json
read_only: true
links:
- mongo
depends_on:
- mongo
watchtower:
image: containrrr/watchtower
container_name: watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: --interval 3600 bot
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "aicbot",
"version": "2.4.1",
"description": "",
"version": "2.4.2",
"description": "Discord Bot for playing music",
"main": "build/main.js",
"scripts": {
"build": "tsc",
"development": "tsc&& cross-env NODE_ENV=development node build/main.js",
"production": "cross-env NODE_ENV=production node build/main.js",
"build": "tsc"
"production": "cross-env NODE_ENV=production node build/main.js"
},
"type": "module",
"keywords": [],
Expand All @@ -15,32 +15,32 @@
"dependencies": {
"@discordjs/opus": "^0.9.0",
"@discordjs/rest": "^1.7.1",
"@discordjs/voice": "^0.16.0",
"@discordjs/voice": "^0.16.1",
"@distube/soundcloud": "^1.3.3",
"@distube/spotify": "^1.5.1",
"@distube/spotify": "^1.6.0",
"@distube/yt-dlp": "^1.1.3",
"@distube/ytdl-core": "^4.13.0",
"@distube/ytdl-core": "^4.13.3",
"cross-env": "7.0.3",
"discord.js": "^14.13.0",
"distube": "^4.1.0",
"discord.js": "^14.14.1",
"distube": "^4.1.1",
"distube-yandex-music-plugin": "^0.2.1",
"dotenv": "^16.3.1",
"dotenv": "^16.4.5",
"i18next": "^22.5.1",
"i18next-fs-backend": "^2.2.0",
"mongoose": "^7.5.2",
"i18next-fs-backend": "^2.3.1",
"mongoose": "^7.6.10",
"node-os-utils": "^1.3.7",
"prism-media": "^1.3.5",
"sodium-native": "^4.0.4",
"sodium-native": "^4.1.1",
"uuid": "^9.0.1",
"zod": "^3.22.2"
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^20.6.2",
"@types/node-os-utils": "^1.3.1",
"@types/uuid": "^9.0.4",
"@types/node": "^20.12.5",
"@types/node-os-utils": "^1.3.4",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.49.0",
"typescript": "^5.2.2"
"eslint": "^8.57.0",
"typescript": "^5.4.4"
}
}
Loading

0 comments on commit 74a3e4b

Please sign in to comment.