From da6756c829447c5bbe8f7c7fa598b7d33fef50ee Mon Sep 17 00:00:00 2001 From: Sebastien Date: Sun, 12 Apr 2020 17:20:46 +0200 Subject: [PATCH] Switch to Github Action --- .github/workflows/build.yml | 54 +++++++++++++++++++++++++++ Dockerfile | 12 +++--- Jenkinsfile | 74 ------------------------------------- build.gradle | 6 +-- 4 files changed, 62 insertions(+), 84 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 Jenkinsfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..17d2552 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,54 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Build and Upload to DockerHub + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build-gradle: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + - name: Upload Jar File + uses: actions/upload-artifact@v2-preview + with: + name: claptrap_jar + path: build/libs/ + build-docker: + runs-on: [ubuntu-latest] + needs: [build-gradle] + steps: + - uses: actions/checkout@v2 + - name: Get build number + id: get_version + run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_RUN_NUMBER}) + - name: Download artifact + uses: actions/download-artifact@v1.0.0 + with: + # Artifact name + name: claptrap_jar + # Destination path + path: build/libs/ + - name: Publish Docker + uses: elgohr/Publish-Docker-Github-Action@master + with: + name: brokenfire/brokendiscordbot + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + tags: "latest,${{ env.RELEASE_VERSION }}" + buildargs: GITHUB_RUN_NUMBER=${{env.RELEASE_VERSION}} diff --git a/Dockerfile b/Dockerfile index 35169d1..a584a5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,11 @@ -FROM debian:latest -RUN apt-get update -RUN apt-get -y upgrade -RUN apt-get -y install openjdk-8-jre openjdk-8-jdk curl wget +FROM openjdk:8-jre-buster WORKDIR /bot_src ARG BUILD_NBR ARG BRANCH_NAME -ADD DownloadLast.sh /bot_src/ -RUN chmod +x DownloadLast.sh -RUN ./DownloadLast.sh ${BRANCH_NAME} ${BUILD_NBR} +ARG BRANCH_NAME +ARG GITHUB_RUN_NUMBER +ADD build/libs/ClaptrapBot-*.jar /bot_src/bot.jar +RUN java -version ENV PORT=8080 ENV TOKEN=10 CMD java -jar bot.jar -t ${TOKEN} diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 7f7cd36..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,74 +0,0 @@ -pipeline { - agent any - stages { - - stage('Clone') { // for display purposes - // Get some code from a GitHub repository - steps { - echo env.BRANCH_NAME - script { - if (env.BRANCH_NAME == 'master') { - git url: 'https://github.com/BrokenFire/BrokenDiscordBot.git', branch: 'master' - } else { - git url: 'https://github.com/BrokenFire/BrokenDiscordBot.git', branch: 'devel' - } - } - } - - - } - stage('Gradle Build'){ - steps{ - script { - if (env.BRANCH_NAME == 'master') { - build job: 'Bot Discord Gradle', wait: true - } else { - build job: 'Bot Discord Gradle devel', wait: true - } - } - } - - } - stage('Build Docker image') { - /* This builds the actual image; synonymous to - * docker build on the command line */ - steps{ - script{ - app = docker.build("brokenfire/brokendiscordbot",'--build-arg BUILD_NBR=${BUILD_NUMBER} --build-arg BRANCH_NAME=${BRANCH_NAME} --rm=true .') - } - - } - - } - stage('Push Docker image') { - /* Finally, we'll push the image with two tags: - * First, the incremental build number from Jenkins - * Second, the 'latest' tag. - * Pushing multiple tags is cheap, as all the layers are reused. */ - steps{ - withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'docker-hub-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) { - sh 'docker login -u $USERNAME -p $PASSWORD' - script { - if (env.BRANCH_NAME == 'master') { - app.push("master") - } else { - app.push("devel") - } - } - } - } - - - - - - } - stage('Cleaning'){ - steps{ - sh "docker image prune -f" - } - - } - } -} - diff --git a/build.gradle b/build.gradle index 1bfa700..b7f11f5 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { def versionObj = new Version(major: 0, minor: 2, revision: 0) group = "net.broken" -archivesBaseName = "BrokenDiscordBot" +archivesBaseName = "ClaptrapBot" version = "$versionObj" sourceCompatibility = 1.8 @@ -23,7 +23,7 @@ jar.doFirst { jar { // delete "${buildDir}/libs/*" - baseName = 'DiscordBot' +// baseName = 'DiscordBot' } @@ -80,7 +80,7 @@ class Version { String major, minor, revision static String getBuild() { - System.getenv("BUILD_NUMBER") ?: System.getProperty("BUILD_NUMBER") ?: + System.getenv("GITHUB_RUN_NUMBER") ?: System.getProperty("BUILD_NUMBER") ?: System.getenv("GIT_COMMIT")?.substring(0, 7) ?: System.getProperty("GIT_COMMIT")?.substring(0, 7) ?:"DEV" }