From 91351238953ebd9a2504ad25f34249c9bf8f1df9 Mon Sep 17 00:00:00 2001 From: Mazo Date: Sun, 13 Jun 2021 16:26:17 +0100 Subject: [PATCH 1/5] Fix publishing docker containers on push (tagged with sha for all pushes, master is tagged with sha, master, latest) --- .github/workflows/publish.yaml | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index a3556bd1..62ee4c47 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -30,19 +30,28 @@ jobs: docker: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Inject slug/short variables - uses: rlespinasse/github-slug-action@v2.x + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 - name: Set variables + id: prep run: | - echo "REPOSITORY=$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV - - name: Build and push Docker image - uses: docker/build-push-action@v2.5.0 + DOCKER_IMAGE=server + REPOSITORY="$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')" + + TAGS="ghcr.io/${REPOSITORY}/${DOCKER_IMAGE}:${GITHUB_SHA}" + if [ "${{ github.ref }}" = "refs/heads/master" ]; then + TAGS="$TAGS,ghcr.io/${REPOSITORY}/${DOCKER_IMAGE}:latest,ghcr.io/${REPOSITORY}/${DOCKER_IMAGE}:master" + fi + + echo ::set-output name=tags::${TAGS} + - name: Log in to GitHub Docker Registry + uses: docker/login-action@v1 with: + registry: ghcr.io username: ${{ github.actor }} - password: ${{ github.token }} - registry: docker.pkg.github.com - repository: ${{ env.REPOSITORY }}/server - tag_with_sha: true - tag_with_ref: true \ No newline at end of file + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build container image + uses: docker/build-push-action@v2 + with: + push: true + tags: ${{ steps.prep.outputs.tags }} \ No newline at end of file From f0d39f99431cbe51683d1a6a0a2fc2be075da2e8 Mon Sep 17 00:00:00 2001 From: Mazo Date: Sun, 13 Jun 2021 23:26:01 +0100 Subject: [PATCH 2/5] Specify if ports are UDP or TCP in dockerfile --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 38cbd924..b373edb9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,8 @@ FROM openjdk:17-slim COPY --from=builder /PSF-LoginServer/server/target/pack/ /usr/local -EXPOSE 51000 -EXPOSE 51001 -EXPOSE 51002 +EXPOSE 51000/udp +EXPOSE 51001/udp +EXPOSE 51002/tcp CMD ["psforever-server"] From 3ab5b12fbef1f2e879c6c17e20d3101a088bb46e Mon Sep 17 00:00:00 2001 From: Mazo Date: Sun, 13 Jun 2021 23:26:47 +0100 Subject: [PATCH 3/5] Split out actions, only run them as required, fix GITHUB_SHA under PR context --- .github/workflows/publish-docs.yml | 30 ++++++++++++++++++++++ .github/workflows/publish.yaml | 41 +++++++++--------------------- .github/workflows/test.yaml | 7 ++++- 3 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/publish-docs.yml diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml new file mode 100644 index 00000000..20554ae5 --- /dev/null +++ b/.github/workflows/publish-docs.yml @@ -0,0 +1,30 @@ +name: Publish Docs +on: + push: + branches: + - master +jobs: + docs: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Cache SBT + uses: actions/cache@v2 + with: + path: | + ~/.ivy2/cache + ~/.sbt + key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }} + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Scala + uses: olafurpg/setup-scala@v12 + - name: Build docs + run: sbt docs/unidoc + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@4.1.4 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: gh-pages + FOLDER: docs/target/scala-2.13/unidoc diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 62ee4c47..f4bda891 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,32 +1,11 @@ -name: Publish -on: [push] +name: Publish Docker Image +on: + push: + branches: + - master + pull_request: + types: [ opened, reopened, synchronize ] jobs: - docs: - if: github.ref == 'refs/heads/master' - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Cache SBT - uses: actions/cache@v2 - with: - path: | - ~/.ivy2/cache - ~/.sbt - key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }} - - name: Checkout - uses: actions/checkout@v2 - - name: Setup Scala - uses: olafurpg/setup-scala@v12 - - name: Build docs - run: sbt docs/unidoc - - name: Deploy to GitHub Pages - uses: JamesIves/github-pages-deploy-action@4.1.4 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BRANCH: gh-pages - FOLDER: docs/target/scala-2.13/unidoc - docker: runs-on: ubuntu-latest steps: @@ -36,7 +15,11 @@ jobs: id: prep run: | DOCKER_IMAGE=server - REPOSITORY="$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')" + REPOSITORY="$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')" # Repository name must be lowercase in image tags + + if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then + GITHUB_SHA=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.head.sha) # GITHUB_SHA is the merge SHA, not the head commit SHA in a PR, replace it. + fi TAGS="ghcr.io/${REPOSITORY}/${DOCKER_IMAGE}:${GITHUB_SHA}" if [ "${{ github.ref }}" = "refs/heads/master" ]; then diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ea2083f0..bba53b3c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,5 +1,10 @@ name: Test -on: [push, pull_request] +on: + push: + branches: + - master + pull_request: + types: [ opened, reopened, synchronize ] jobs: test: runs-on: ubuntu-latest From 667e76a5ad25a7efe8223afe1055dd696a931e02 Mon Sep 17 00:00:00 2001 From: Mazo Date: Sun, 20 Jun 2021 18:51:52 +0100 Subject: [PATCH 4/5] Authenticate to ghcr.io as github.repository_owner --- .github/workflows/publish.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index f4bda891..32b1a112 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -31,7 +31,7 @@ jobs: uses: docker/login-action@v1 with: registry: ghcr.io - username: ${{ github.actor }} + username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build container image uses: docker/build-push-action@v2 From a348b43e92972890cf0aee2cde19e3a85bbc7968 Mon Sep 17 00:00:00 2001 From: Mazo Date: Sun, 20 Jun 2021 20:08:54 +0100 Subject: [PATCH 5/5] Publish image only on master push --- .github/workflows/publish.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 32b1a112..1942c79e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -3,8 +3,6 @@ on: push: branches: - master - pull_request: - types: [ opened, reopened, synchronize ] jobs: docker: runs-on: ubuntu-latest