diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..a7cba4ae --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,49 @@ +name: Publish to Docker Hub + +on: + workflow_dispatch: + push: + tags: + - 'v*' + release: + types: [published] + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ vars.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ vars.DOCKER_USERNAME }}/v2ray-web-manager + tags: | + type=raw,value=latest + type=ref,event=tag + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: ./ + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f82f8639..c956a98f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,40 @@ -FROM openjdk:8-jre +# Stage 1: Fetch dependencies using a smaller base image with wget +FROM alpine:latest AS fetcher +RUN apk add --no-cache wget unzip + +# Download external files efficiently +RUN wget -c https://glare.now.sh/master-coder-ll/v2ray-web-manager/admin -O admin.jar \ + && wget -c https://glare.now.sh/master-coder-ll/v2ray-manager-console/dist -O dist.zip \ + && wget -c https://glare.now.sh/master-coder-ll/v2ray-web-manager/v2ray-proxy -O v2ray-proxy.jar \ + && unzip dist.zip -d ./web/ + +# Stage 2: Main application image +FROM openjdk:8-jre-slim + +# Install nginx and configure timezone RUN set -x && \ echo "Asia/Shanghai" > /etc/timezone && \ apt-get update && \ - apt-get install -y nginx && \ - mkdir -p /opt/jar/db/ && \ - chown 1000:nogroup /opt/jar/db/ && \ - mkdir -p /opt/jar/web/ && \ - chown 1000:nogroup /opt/jar/web/ && \ - mkdir -p /opt/conf/ && \ - chown 1000:nogroup /opt/conf/ - -ADD --chown=1000:nogroup ./admin.jar /opt/jar/admin.jar -ADD --chown=1000:nogroup ./dist.zip /opt/jar/dist.zip -ADD --chown=1000:nogroup ./v2ray-proxy.jar /opt/jar/v2ray-proxy.jar -ADD --chown=1000:nogroup ./conf/admin.yaml /opt/conf/admin.yaml -ADD --chown=1000:nogroup ./conf/proxy.yaml /opt/conf/proxy.yaml -ADD --chown=1000:nogroup ./conf/config.json /opt/jar/config.json -ADD --chown=1000:nogroup ./init.sh /opt/jar/run.sh -ADD --chown=root:root ./conf/v2ray-mng.conf /etc/nginx/conf.d/default.conf + apt-get install -y nginx + +# Copy downloaded files from the first stage +COPY --from=fetcher admin.jar v2ray-proxy.jar /opt/jar/ +COPY --from=fetcher web /opt/jar/web/ + +# Create directories efficiently +RUN mkdir -p /opt/jar/db /opt/conf && \ + chown 1000:nogroup /opt/jar/db /opt/jar/web /opt/conf + +# Copy local files directly +COPY conf/admin.yaml conf/proxy.yaml conf/config.json /opt/conf/ +COPY conf/v2ray-mng.conf /etc/nginx/conf.d/default.conf +COPY init.sh /opt/jar/run.sh +# Unzip and set permissions in a single RUN command RUN cd /opt/jar/ && \ - unzip dist.zip -d /opt/jar/web/ && \ - chmod +x /opt/jar/admin.jar && \ - chmod +x /opt/jar/v2ray-proxy.jar && \ - chmod +x /opt/jar/run.sh + chmod +x /opt/jar/admin.jar /opt/jar/v2ray-proxy.jar /opt/jar/run.sh +# Set working directory and default command WORKDIR /opt/jar/ -CMD ["/bin/sh", "run.sh"] \ No newline at end of file +CMD ["/bin/sh", "run.sh"]