Skip to content

Commit

Permalink
添加 docker 打包工作
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Oct 7, 2024
1 parent b5d253a commit da0dfb7
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build_maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Maven Build

on:
workflow_call:
secrets:
INSTALL4J_LICENSE:
required: true
jobs:
Maven:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "21"
cache: 'maven'
cache-dependency-path: '**/pom.xml'
- name: Build with Maven
run: mvn -B clean package --file pom.xml
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: maven-dist
path: |
target/*.jar
id: project
62 changes: 62 additions & 0 deletions .github/workflows/jvm-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI (push)

on:
push:
workflow_dispatch:
jobs:
CI:
uses: ./.github/workflows/build_maven.yml
secrets: inherit
Build_Docker:
needs: CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: maven-dist
path: target
- name: Set Up QEMU
uses: docker/setup-qemu-action@v3
- name: Set Up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ghostchu/sparkle-snapshot
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,ci-jvm-universal
type=raw,ci
type=sha
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
push: true
platforms: |
linux/amd64
linux/arm64/v8
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}-jvm-universal
cache-from: type=gha
cache-to: type=gha,mode=max
106 changes: 106 additions & 0 deletions .github/workflows/jvm-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Release

on:
workflow_dispatch:
release:
types:
- published
jobs:
Build_Executable:
permissions:
contents: write
checks: write
actions: read
issues: read
packages: write
pull-requests: read
repository-projects: read
statuses: read
secrets: inherit
uses: ./.github/workflows/build_maven.yml
Upload_Artifacts:
needs: [ Build_Executable ]
permissions:
contents: write
checks: write
actions: read
issues: read
packages: write
pull-requests: read
repository-projects: read
statuses: read
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: maven-dist
path: target/
- uses: alexellis/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
asset_paths: '["target/*.jar"]'
Build_Docker:
permissions:
contents: write
checks: write
actions: read
issues: read
packages: write
pull-requests: read
repository-projects: read
statuses: read
needs: Build_Executable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: maven-dist
path: target
- name: Set Up QEMU
uses: docker/setup-qemu-action@v3
- name: Set Up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ghostchu/peerbanhelper
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,latest-jvm-universal
type=raw,latest
type=sha
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
push: true
platforms: |
linux/amd64
linux/arm64/v8
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}-jvm-universal
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
GIT_HASH=${{ github.sha }}
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM docker.io/eclipse-temurin:21-jre-alpine
LABEL maintainer="https://github.com/PBH-BTN/Sparkle"
COPY target/sparkle-0.0.1-SNAPSHOT.jar /app/sparkle.jar
USER 0
ENV TZ=UTC
WORKDIR /app
VOLUME /tmp
ENV PATH="${JAVA_HOME}/bin:${PATH}"
ENTRYPOINT ["java","-Xmx2G","-XX:+UseG1GC", "-XX:+UseStringDeduplication","-XX:+ShrinkHeapInSteps","-jar","PeerBanHelper.jar"]

0 comments on commit da0dfb7

Please sign in to comment.