diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 00000000..7584e614 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,66 @@ +name: Docker + +on: + push: + branches: [ "main" ] + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1 + with: + cosign-release: 'v2.1.1' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=sha + type=raw,value=latest + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + 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 edb45cf2..0acbba0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,13 @@ -FROM maven:3.8.5-openjdk-17 - -ARG user=spring -ARG group=spring +FROM maven:3.9-eclipse-temurin-17-alpine AS builder ENV SPRING_HOME=/home/spring -RUN groupadd -g 1000 ${group} \ - && useradd -d "$SPRING_HOME" -u 1000 -g 1000 -m -s /bin/bash ${user} \ - && mkdir -p $SPRING_HOME/config \ - && mkdir -p $SPRING_HOME/logs \ - && chown -R ${user}:${group} $SPRING_HOME/config $SPRING_HOME/logs +RUN mkdir -p $SPRING_HOME/config \ + && mkdir -p $SPRING_HOME/logs # Railway 不支持使用 VOLUME, 本地需要构建时,取消下一行的注释 # VOLUME ["$SPRING_HOME/config", "$SPRING_HOME/logs"] -USER ${user} WORKDIR $SPRING_HOME COPY . . @@ -23,6 +16,8 @@ RUN mvn clean package \ && mv target/midjourney-proxy-*.jar ./app.jar \ && rm -rf target +FROM amazoncorretto:17-alpine +COPY --from=builder /home/spring/app.jar /home/spring/app.jar EXPOSE 8080 9876 ENV JAVA_OPTS -XX:MaxRAMPercentage=85 -Djava.awt.headless=true -XX:+HeapDumpOnOutOfMemoryError \ @@ -31,4 +26,4 @@ ENV JAVA_OPTS -XX:MaxRAMPercentage=85 -Djava.awt.headless=true -XX:+HeapDumpOnOu -Dcom.sun.management.jmxremote.authenticate=false -Dlogging.file.path=/home/spring/logs \ -Dserver.port=8080 -Duser.timezone=Asia/Shanghai -ENTRYPOINT ["bash","-c","java $JAVA_OPTS -jar app.jar"] +ENTRYPOINT ["bash","-c","java $JAVA_OPTS -jar app.jar"] \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..e25d9649 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3" + +services: + midjourney-proxy: + image: ghcr.io/novicezk/midjourney-proxy:latest + container_name: midjourney-proxy + restart: unless-stopped + ports: + - 8080:8080 + volumes: + - ./config:/home/spring/config \ No newline at end of file