try build docker image

This commit is contained in:
KagurazakaNyaa 2024-10-12 16:38:48 +08:00
parent 43bb852bb6
commit 4348d72e1c
5 changed files with 139 additions and 0 deletions

1
.dockerignore Symbolic link
View File

@ -0,0 +1 @@
.gitignore

60
.github/workflows/docker.yml vendored Normal file
View File

@ -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 }}

28
docker-compose.yml Normal file
View File

@ -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

View File

@ -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" ]

23
dockerfile/web.dockerfile Normal file
View File

@ -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" ]