diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml deleted file mode 100644 index 49feddd..0000000 --- a/.github/workflows/dockerhub.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Dockerhub - -on: - push: - branches: - - main - workflow_dispatch: - -permissions: - contents: read - -jobs: - test: - name: Uploading Img - timeout-minutes: 30 - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Building Docker Image - run: docker build -t ${{ secrets.username }}/erp-backend:prod . - - name: DockerHub Login - run: docker login -u "${{ secrets.username }}" -p "${{ secrets.pass }}" - - name: Uploading Image to DockerHub - run: docker push ${{ secrets.username }}/erp-backend:prod diff --git a/.github/workflows/ghcrPush.yml b/.github/workflows/ghcrPush.yml new file mode 100644 index 0000000..ef114c2 --- /dev/null +++ b/.github/workflows/ghcrPush.yml @@ -0,0 +1,42 @@ +name: Publishing Docker Image to ghcr.io + +on: + push: + branches: + - main + tags: + - v* + workflow_dispatch: + pull_request: + +jobs: + push: + name: Building Image and pushing + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + - name: Build image + run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" + - name: Log in to registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --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]') +This changes all uppercase characters to lowercase. + + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') +This strips the git ref prefix from the version. + + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') +This strips the "v" prefix from the tag name. + + [ "$VERSION" == "main" ] && VERSION=latest + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION