diff --git a/.github/release.yml b/.github/release.yml index 959d2a5b..21258c8d 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -19,4 +19,4 @@ changelog: - deprecated - title: Other Changes labels: - - "*" \ No newline at end of file + - "*" diff --git a/.github/workflows/docker-dev.yml b/.github/workflows/docker-dev.yml deleted file mode 100644 index 3901cbab..00000000 --- a/.github/workflows/docker-dev.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Docker CI (staging) - -on: - push: - branches: [dev] - -env: - REGISTRY: ghcr.io - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set env - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - name: Log into registry ${{ env.REGISTRY }} - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push docker - run: | - docker build -f ./Dockerfile . --tag ${{ env.REGISTRY }}/fsr5-fhaachen/portals:dev - docker push ${{ env.REGISTRY }}/fsr5-fhaachen/portals:dev \ No newline at end of file diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 2cfae744..743b7fb2 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -1,11 +1,17 @@ -name: Docker CI (release) +name: Docker Release on: release: - types: [published] + types: + - published + push: + branches: + - dev env: - REGISTRY: ghcr.io + IMAGE_REGISTRY: ghcr.io + IMAGE_PATH: ${{ github.repository }} + IMAGE_TAG: ${{ github.ref_name }} jobs: build: @@ -13,16 +19,37 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Set env - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - name: Log into registry ${{ env.REGISTRY }} + - name: Get latest release + id: latest_release + uses: pozetroninc/github-action-get-latest-release@master + with: + repository: ${{ github.repository }} + excludes: prerelease, draft + - name: Docker Login uses: docker/login-action@v2 with: - registry: ${{ env.REGISTRY }} + registry: ${{ env.IMAGE_REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push docker - run: | - docker build -f ./Dockerfile . --tag ${{ env.REGISTRY }}/fsr5-fhaachen/portals:${{ env.RELEASE_VERSION }} --tag ${{ env.REGISTRY }}/fsr5-fhaachen/portals:latest - docker push ${{ env.REGISTRY }}/fsr5-fhaachen/portals:${{ env.RELEASE_VERSION }} - docker push ${{ env.REGISTRY }}/fsr5-fhaachen/portals:latest \ No newline at end of file + - name: Build and push (latest release) + uses: docker/build-push-action@v4 + if: ${{ github.event_name == 'release' && steps.latest_release.outputs.release == github.ref_name }} # run only on latest release + with: + push: true + tags: + - ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_PATH }}:${{ env.IMAGE_TAG }} + - ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_PATH }}:latest + - name: Build and push (release) + uses: docker/build-push-action@v4 + if: ${{ github.event_name == 'release' && steps.latest_release.outputs.release != github.ref_name }} # run only on release (not latest) + with: + push: true + tags: + - ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_PATH }}:${{ env.IMAGE_TAG }} + - name: Build and push (push) + uses: docker/build-push-action@v4 + if: ${{ github.event_name == 'push' }} # run only on push (to dev) + with: + push: true + tags: + - ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_PATH }}:${{ env.IMAGE_TAG }}