From 809b55b6ac9a147749649d116f50dc25cf26d9ef Mon Sep 17 00:00:00 2001 From: Tobias Persson Date: Mon, 25 Nov 2024 13:05:11 +0100 Subject: [PATCH] Add a docker build workflow --- .github/workflows/docker.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..d3de91f --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,36 @@ +name: Build and push docker image + +on: + pull_request_target: + branches: [ "main" ] + types: + - closed + workflow_dispatch: + +jobs: + build_docker: + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build app image + run: docker build . --tag image + + - name: Log into registry + run: echo "${{ secrets.REGISTRYPASSWORD }}" | docker login registry.nordix.org -u ${{ secrets.REGISTRYUSERNAME }} --password-stdin + + - name: Push app image + id: image + run: | + IMAGE_ID=registry.nordix.org/eiffel/etos-environment-provider + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # Use Docker `latest` tag convention + [ "$VERSION" == "main" ] && VERSION=$(echo ${{ github.sha }} | cut -c1-8) + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag image $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION + echo $IMAGE_ID:$VERSION