diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml deleted file mode 100644 index 2efdbbcf2..000000000 --- a/.github/workflows/gradle.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Halo CI - -on: - pull_request: - push: - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - with: - submodules: true - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Cache Gradle - id: cache-gradle - uses: actions/cache@v1 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: | - ${{ runner.os }}-gradle- - - name: Test with Gradle - run: ./gradlew test - - name: Build with Gradle - run: ./gradlew build -x test diff --git a/.github/workflows/halo.yml b/.github/workflows/halo.yml new file mode 100644 index 000000000..193c7f5b5 --- /dev/null +++ b/.github/workflows/halo.yml @@ -0,0 +1,182 @@ +name: Halo CI + +on: + pull_request: + paths: + - '**' + - '!**.md' + push: + branches: + - '**' + paths: + - '**' + - '!**.md' + release: + types: # This configuration does not affect the page_build event above + - created + +jobs: + check: + runs-on: ubuntu-latest + # Default steps + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + + - name: Cache Gradle wrapper + id: cache-gradle-wrapper + uses: actions/cache@v2.1.3 + with: + path: ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-dependencies- + + - name: Cache Dependencies + id: cache-dependencies + uses: actions/cache@v2.1.3 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-dependencies-${{ hashFiles('**/*.gradle') }} + restore-keys: | + ${{ runner.os }}-dependencies- + + - name: Check And Test + run: ./gradlew check + build: + runs-on: ubuntu-latest + needs: check + if: github.event_name == 'release' + # Default steps + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Cache Gradle wrapper + id: cache-gradle-wrapper + uses: actions/cache@v2.1.3 + with: + path: ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-dependencies- + - name: Cache Dependencies + id: cache-dependencies + uses: actions/cache@v2.1.3 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-dependencies-${{ hashFiles('**/*.gradle') }} + restore-keys: | + ${{ runner.os }}-dependencies- + + - name: Build with Gradle + run: ./gradlew clean build -x test + + - name: Archive halo jar + uses: actions/upload-artifact@v2 + with: + name: halo-jar + path: build/libs + retention-days: 1 + github-release: + runs-on: ubuntu-latest + needs: build + if: github.event_name == 'release' + steps: + - name: Download halo jar + uses: actions/download-artifact@v2 + with: + name: halo-jar + path: build/libs + - name: Get Name of Artifact + id: get_artifact + run: | + ARTIFACT_PATHNAME=$(ls build/libs/*.jar | head -n 1) + ARTIFACT_NAME=$(basename ${ARTIFACT_PATHNAME}) + echo "Artifact pathname: ${ARTIFACT_PATHNAME}" + echo "Artifact name: ${ARTIFACT_NAME}" + echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV + echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV + echo "RELEASE_ID=${{ github.event.release.id }}" >> $GITHUB_ENV + - name: Upload a Release Asset + uses: actions/github-script@v2 + if: github.event_name == 'release' + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + console.log('environment', process.versions); + + const fs = require('fs').promises; + + const { repo: { owner, repo }, sha } = context; + console.log({ owner, repo, sha }); + + const releaseId = process.env.RELEASE_ID + const artifactPathName = process.env.ARTIFACT_PATHNAME + const artifactName = process.env.ARTIFACT_NAME + console.log('Releasing', releaseId, artifactPathName, artifactName) + + await github.repos.uploadReleaseAsset({ + owner, repo, + release_id: releaseId, + name: artifactName, + data: await fs.readFile(artifactPathName) + }); + docker-release: + runs-on: ubuntu-latest + needs: build + if: github.event_name == 'release' + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Download halo jar + uses: actions/download-artifact@v2 + with: + name: halo-jar + path: build/libs + - name: Cache Gradle wrapper + id: cache-gradle-wrapper + uses: actions/cache@v2.1.3 + with: + path: ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-dependencies- + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Build docker image + run: | + docker info + docker images + export DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }} + export DOCKER_TOKEN=${{ secrets.DOCKER_TOKEN }} + export DOCKER_IMAGE_NAME=${{ secrets.DOCKER_IMAGE_NAME }} + export TAG_LATEST=false + echo "Building and pushing with version tag." + ./gradlew bootBuildImage -x bootJar --publishImage + PRE_RELEASE=${{ github.event.release.prerelease }} + if ! $PRE_RELEASE + then + echo "Building and pushing with latest tag." + export TAG_LATEST=true + ./gradlew bootBuildImage -x bootJar --publishImage + else + echo "Skipped building and pushing with latest tag due to pre-release." + fi + docker images \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8b2eca5f3..000000000 --- a/.travis.yml +++ /dev/null @@ -1,49 +0,0 @@ -language: java -jdk: - - openjdk:11 -before_cache: - - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ -cache: - directories: - - $HOME/.gradle/caches/ - - $HOME/.gradle/wrapper/ - - $TRAVIS_BUILD_DIR/build/libs/ -dist: trusty -jobs: - include: - - stage: test - script: ./gradlew check - - stage: build - script: ./gradlew clean build -x test - - stage: Build Docker Image for Release - script: ./scripts/docker-build-release.sh - - stage: Build Docker Image for Dev - script: ./scripts/docker-build-dev.sh - - stage: GitHub Release - script: echo "Deploying to GitHub releases ..." && pwd - deploy: - provider: releases - api_key: $GITHUB_OAUTH_TOKEN - file_glob: true - file: $TRAVIS_BUILD_DIR/build/libs/* - skip_cleanup: true - on: - tags: true -stages: - - test - - build - - name: GitHub Release - if: tag =~ /^v\d+\.\d+(\.\d+)?(-\S*)?$/ - - name: Build Docker Image for Release - if: tag =~ /^v\d+\.\d+(\.\d+)?(-release)?$/ - - name: Build Docker Image for Dev - if: tag =~ /^v\d+\.\d+(\.\d+)?-(beta|alpha)+(\.\d+)?$/ -branches: - only: - - master - - dev - - /^v\d+\.\d+(\.\d+)?(-\S*)?$/ -notifications: - webhooks: - - https://fathomless-fjord-24024.herokuapp.com/notify diff --git a/Dockerfile b/Dockerfile index dcce11f32..fdd7e1a02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,17 @@ FROM adoptopenjdk/openjdk11-openj9 VOLUME /tmp -ARG JAR_FILE=build/libs/halo.jar -ARG PORT=8090 +ARG JAR_FILE=build/libs/*.jar ARG TIME_ZONE=Asia/Shanghai -ENV TZ=${TIME_ZONE} -ENV JVM_XMS="256m" -ENV JVM_XMX="256m" +ENV JVM_XMS="256m" \ + JVM_XMX="256m" \ + JVM_OPTS="" \ + TZ=${TIME_ZONE} + COPY ${JAR_FILE} halo.jar -EXPOSE ${PORT} +EXPOSE 8090 -ENTRYPOINT java -Xms${JVM_XMS} -Xmx${JVM_XMX} -Djava.security.egd=file:/dev/./urandom -server -jar halo.jar +ENTRYPOINT java -Xms${JVM_XMS} -Xmx${JVM_XMX} ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -server -jar halo.jar \ No newline at end of file diff --git a/build.gradle b/build.gradle index 37e3c57f3..862e5e765 100644 --- a/build.gradle +++ b/build.gradle @@ -37,8 +37,39 @@ configurations { bootJar { manifest { - attributes("Implementation-Title": "Halo Application", - "Implementation-Version": version) + attributes "Implementation-Title": "Halo Application", + "Implementation-Version": archiveVersion + } +} + +bootBuildImage.doFirst { + // check data + assert System.getenv("DOCKER_USERNAME") != null + assert System.getenv("DOCKER_TOKEN") != null +} + +bootBuildImage { + // prepare data + def tagLatest = Boolean.valueOf(System.getenv("TAG_LATEST")) + def dockerImageName = System.getenv("DOCKER_IMAGE_NAME") + def dockerUsername = System.getenv("DOCKER_USERNAME") + def dockerToken = System.getenv("DOCKER_TOKEN") + + if (dockerImageName == null) { + dockerImageName = "${dockerUsername}/halo" + } + if (!tagLatest) { + dockerImageName = "${dockerImageName}:${project.version}" + } + + // config plugin + imageName = "${dockerImageName}" + docker { + publishRegistry { + username = "${dockerUsername}" + password = "${dockerToken}" + email = "hi@halo.run" + } } }