From 754cf1a1b081ed4712028d28b851d65db9e80a32 Mon Sep 17 00:00:00 2001 From: Mikolaj Wojciech Gorski Date: Mon, 10 Feb 2025 21:18:18 +0100 Subject: [PATCH 1/2] Added a Dockerfile for docker deployment, and an action for compiling a docker image --- .github/workflows/build_docker.yaml | 45 +++++++++++++++++++++++++++++ Dockerfile | 25 ++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 .github/workflows/build_docker.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/build_docker.yaml b/.github/workflows/build_docker.yaml new file mode 100644 index 0000000..2866749 --- /dev/null +++ b/.github/workflows/build_docker.yaml @@ -0,0 +1,45 @@ +name: Docker Build and Push + +on: + push: + branches: + - main + +env: + IMAGE_NAME: polaris-bot + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + # Checkout the repository + - name: Checkout code + uses: actions/checkout@v4 + + # Log in to GitHub Container Registry + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} + + # Build and push the Docker image + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..60c84b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# Use Node.js LTS with full build tools +FROM node:18-bullseye + +# Set working directory +WORKDIR /app + +# Install Python and build dependencies +RUN apt-get update && \ + apt-get install -y python3 make g++ && \ + rm -rf /var/lib/apt/lists/* + +# Copy package files +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy all source files +COPY . . + +# Expose web server port +EXPOSE 6880 + +# Start the bot +CMD ["node", "polaris.js"] From bdbcc89d91274ad4ef2345f9b800e3a7465509f1 Mon Sep 17 00:00:00 2001 From: Mikolaj Wojciech Gorski Date: Tue, 11 Feb 2025 00:04:46 +0100 Subject: [PATCH 2/2] Made a docker compose that takes care of both the bot and db. --- docker-compose.yaml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 docker-compose.yaml diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..446ec85 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,34 @@ +version: '3.8' +services: + polaris: + image: ghcr.io/gdcolon/polaris-bot:main + container_name: polaris-bot + restart: unless-stopped + ports: + - "6880:6880" + volumes: + - ./config.json:/app/config.json + - ./.env:/app/.env + environment: + - NODE_ENV=production + depends_on: + - mongo + networks: + - polaris-net + + mongo: + image: mongo:6 + container_name: polaris-mongo + restart: unless-stopped + environment: + - MONGO_INITDB_ROOT_USERNAME=${MONGO_USER} + - MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASS} + - MONGO_INITDB_DATABASE=${MONGO_DB} + volumes: + - ./mongo_data:/data/db + networks: + - polaris-net + +networks: + polaris-net: + driver: bridge