From 4348d72e1cbf09360b7a1b415660520fcd8e51d8 Mon Sep 17 00:00:00 2001 From: KagurazakaNyaa Date: Sat, 12 Oct 2024 16:38:48 +0800 Subject: [PATCH] try build docker image --- .dockerignore | 1 + .github/workflows/docker.yml | 60 ++++++++++++++++++++++++++++++++++++ docker-compose.yml | 28 +++++++++++++++++ dockerfile/daemon.dockerfile | 27 ++++++++++++++++ dockerfile/web.dockerfile | 23 ++++++++++++++ 5 files changed, 139 insertions(+) create mode 120000 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 docker-compose.yml create mode 100644 dockerfile/daemon.dockerfile create mode 100644 dockerfile/web.dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 00000000..3e4e48b0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..32072ef5 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,60 @@ +name: Release Docker Build + +on: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Docker meta web + id: meta_web + uses: docker/metadata-action@v5 + with: + images: | + name=ghcr.io/${{ github.repository }}-web + name=${{ github.repository }}-web,enable=false + + - name: Docker meta daemon + id: meta_daemon + uses: docker/metadata-action@v5 + with: + images: | + name=ghcr.io/${{ github.repository }}-daemon + name=${{ github.repository }}-daemon,enable=false + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to ghcr.io + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # - name: Login to DockerHub + # uses: docker/login-action@v3 + # with: + # username: ${{ secrets.DOCKER_HUB_USERNAME }} + # password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build and Push Web + uses: docker/build-push-action@v5 + with: + file: dockerfile/web.dockerfile + push: true + tags: ${{ steps.meta_web.outputs.tags }} + labels: ${{ steps.meta_web.outputs.labels }} + + - name: Build and Push Daemon + uses: docker/build-push-action@v5 + with: + file: dockerfile/daemon.dockerfile + push: true + tags: ${{ steps.meta_daemon.outputs.tags }} + labels: ${{ steps.meta_daemon.outputs.labels }} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..e012bdfc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +services: + web: + build: + context: . + dockerfile: dockerfile/web.dockerfile + image: ghcr.io/MCSManager/MCSManager-web:latest + ports: + - "80:23333" + volumes: + - /etc/localtime:/etc/localtime:ro + - /opt/mcsmanager/data/web/data:/opt/mcsmanager/web/data + - /opt/mcsmanager/data/web/logs:/opt/mcsmanager/web/logs + + daemon: + build: + context: . + dockerfile: dockerfile/daemon.dockerfile + image: ghcr.io/MCSManager/MCSManager-daemon:latest + restart: unless-stopped + ports: + - "24444:24444" + environment: + - MCSM_INSTANCES_BASE_PATH=/opt/mcsmanager/daemon/data/InstanceData + volumes: + - /etc/localtime:/etc/localtime:ro + - /opt/mcsmanager/data/daemon/data:/opt/mcsmanager/daemon/data + - /opt/mcsmanager/data/daemon/logs:/opt/mcsmanager/daemon/logs + - /var/run/docker.sock:/var/run/docker.sock diff --git a/dockerfile/daemon.dockerfile b/dockerfile/daemon.dockerfile new file mode 100644 index 00000000..26646fb2 --- /dev/null +++ b/dockerfile/daemon.dockerfile @@ -0,0 +1,27 @@ +FROM node:lts AS builder + +WORKDIR /src +COPY . /src + +RUN chmod a+x ./install-dependents.sh &&\ + chmod a+x ./build.sh &&\ + ./install-dependents.sh &&\ + ./build.sh + +RUN wget --input-file=lib-urls.txt --directory-prefix=production-code/daemon/lib/ + +FROM node:lts + +WORKDIR /opt/mcsmanager/daemon + +COPY --from=builder /src/production-code/daemon/ /opt/mcsmanager/daemon/ + +RUN npm install --production + +EXPOSE 24444 + +ENV MCSM_INSTANCES_BASE_PATH=/opt/mcsmanager/daemon/data/InstanceData + +VOLUME ["/opt/mcsmanager/daemon/data", "/opt/mcsmanager/daemon/logs"] + +CMD [ "app.js", "--max-old-space-size=8192" ] \ No newline at end of file diff --git a/dockerfile/web.dockerfile b/dockerfile/web.dockerfile new file mode 100644 index 00000000..5e6820df --- /dev/null +++ b/dockerfile/web.dockerfile @@ -0,0 +1,23 @@ +FROM node:lts AS builder + +WORKDIR /src +COPY . /src + +RUN chmod a+x ./install-dependents.sh &&\ + chmod a+x ./build.sh &&\ + ./install-dependents.sh &&\ + ./build.sh + +FROM node:lts + +WORKDIR /opt/mcsmanager/web + +COPY --from=builder /src/production-code/web/ /opt/mcsmanager/web/ + +RUN npm install --production + +EXPOSE 23333 + +VOLUME ["/opt/mcsmanager/web/data", "/opt/mcsmanager/web/logs"] + +CMD [ "app.js", "--max-old-space-size=8192" ]