From 4ac8c3a08bfdc5f9a1693ee1922243d1723e408d Mon Sep 17 00:00:00 2001 From: Tim203 Date: Thu, 11 Jul 2024 20:24:53 +0200 Subject: [PATCH] Initial attempt to create global api images --- .github/workflows/build-publish.yml | 39 ++++++++++++++++++++ Dockerfile | 12 ++++--- Jenkinsfile | 56 ----------------------------- build.sh | 2 +- 4 files changed, 47 insertions(+), 62 deletions(-) create mode 100644 .github/workflows/build-publish.yml delete mode 100644 Jenkinsfile diff --git a/.github/workflows/build-publish.yml b/.github/workflows/build-publish.yml new file mode 100644 index 0000000..87e5f6e --- /dev/null +++ b/.github/workflows/build-publish.yml @@ -0,0 +1,39 @@ +name: Build and Publish + +on: + push: + branches: + - master + - dev/1.0.2 + +env: + MIX_ENV: prod + IMAGE_NAME: global_api + +jobs: + push: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - uses: actions/checkout@v4 + - name: Build image + run: docker build . --target release -t $IMAGE_NAME --label "run-number=${GITHUB_RUN_ID}" --build-arg MIX_ENV + - name: Registry login + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION + - name: Notify Discord + if: ${{ (success() || failure()) && github.repository == 'GeyserMC/global_api' }} + uses: Tim203/actions-git-discord-webhook@main + with: + webhook_url: ${{ secrets.DISCORD_WEBHOOK }} diff --git a/Dockerfile b/Dockerfile index 66b404b..ce4b7f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,13 +53,12 @@ RUN mix release RUN 7z a global_api.7z /app/_build/$MIX_ENV/rel/global_api -FROM scratch AS release +FROM scratch AS release_7z COPY --from=bake_release /app/global_api.7z . CMD ["/bin/bash"] - FROM setup_base AS dev RUN apt install -y inotify-tools @@ -68,7 +67,10 @@ EXPOSE 80 443 CMD npm i --prefix ./assets && mix deps.get && mix ecto.migrate && mix phx.server -FROM debian:bullseye AS prod -#todo use the release and run it +FROM debian:bullseye AS release +ARG MIX_ENV +WORKDIR /app + +COPY --from=bake_release /app/_build/$MIX_ENV/rel/global_api . -CMD ["/bin/bash"] \ No newline at end of file +CMD /app/bin/global_api start \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index ec8ca7f..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,56 +0,0 @@ -pipeline { - agent any - - stages { - stage ('Build') { - steps { - sh './build.sh' - } - post { - success { - archiveArtifacts artifacts: '*.7z', fingerprint: true - } - } - } - } - - post { - always { - script { - def changeLogSets = currentBuild.changeSets - def message = "**Changes:**" - - if (changeLogSets.size() == 0) { - message += "\n*No changes.*" - } else { - def repositoryUrl = scm.userRemoteConfigs[0].url.replace(".git", "") - def count = 0; - def extra = 0; - for (int i = 0; i < changeLogSets.size(); i++) { - def entries = changeLogSets[i].items - for (int j = 0; j < entries.length; j++) { - if (count <= 10) { - def entry = entries[j] - def commitId = entry.commitId.substring(0, 6) - message += "\n - [`${commitId}`](${repositoryUrl}/commit/${entry.commitId}) ${entry.msg}" - count++ - } else { - extra++; - } - } - } - - if (extra != 0) { - message += "\n - ${extra} more commits" - } - } - - env.changes = message - } - deleteDir() - withCredentials([string(credentialsId: 'geyser-discord-webhook', variable: 'DISCORD_WEBHOOK')]) { - discordSend description: "**Build:** [${currentBuild.id}](${env.BUILD_URL})\n**Status:** [${currentBuild.currentResult}](${env.BUILD_URL})\n${changes}", footer: 'Open Collaboration Jenkins', link: env.BUILD_URL, successful: currentBuild.resultIsBetterOrEqualTo('SUCCESS'), title: "${env.JOB_NAME} #${currentBuild.id}", webhookURL: DISCORD_WEBHOOK - } - } - } -} \ No newline at end of file diff --git a/build.sh b/build.sh index 57b80a8..b562af7 100755 --- a/build.sh +++ b/build.sh @@ -3,7 +3,7 @@ set -e export MIX_ENV=prod -docker build -t global_api_release --target release . --build-arg MIX_ENV +docker build -t global_api_release --target release_7z . --build-arg MIX_ENV id=$(docker create global_api_release)