From b07425c362da99f962d06734148b5a35b6a6945c Mon Sep 17 00:00:00 2001 From: Tobias Persson Date: Mon, 27 Nov 2023 10:32:09 +0100 Subject: [PATCH] Add CI for environment provider (#83) --- .github/workflows/build-push.yml | 82 ++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/workflows/build-push.yml diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml new file mode 100644 index 0000000..5619369 --- /dev/null +++ b/.github/workflows/build-push.yml @@ -0,0 +1,82 @@ +name: Build and push + +on: + pull_request_target: + branches: [ "main" ] + types: + - closed + workflow_dispatch: + +jobs: + build_api: + 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 + echo "::set-output name=version::$VERSION" + - name: Update manifests + uses: fjogeleit/yaml-update-action@main + with: + valueFile: 'manifests/base/api/deployment.yaml' + propertyPath: 'spec.template.spec.containers[0].image' + value: registry.nordix.org/eiffel/etos-environment-provider:${{ steps.image.outputs.version }} + branch: main + commitChange: true + message: Updating API manifest image to version ${{ steps.image.outputs.version }} + build_worker: + 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 . -f Dockerfile.workers --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-worker + # 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 + echo "::set-output name=version::$VERSION" + - name: Update manifests + uses: fjogeleit/yaml-update-action@main + with: + valueFile: 'manifests/base/worker/deployment.yaml' + propertyPath: 'spec.template.spec.containers[0].image' + value: registry.nordix.org/eiffel/etos-environment-provider-worker:${{ steps.image.outputs.version }} + branch: main + commitChange: true + message: Updating SSE manifest image to version ${{ steps.image.outputs.version }}