Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[greatbody] Optimize Dockerfile and add pipeline to build it. #249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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
54 changes: 32 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
CMD ["/bin/sh", "run.sh"]