diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 9ed5de47..f0e75657 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -21,15 +21,15 @@ jobs: strategy: matrix: include: - - host_namespace: ghcr.io/everest/everest-demo - image_name: manager - context: ./manager - host_namespace: ghcr.io/everest/everest-demo image_name: mqtt-server context: ./mosquitto - host_namespace: ghcr.io/everest/everest-demo image_name: nodered context: ./nodered + - host_namespace: ghcr.io/everest/everest-demo + image_name: manager + context: ./manager steps: - name: Checkout @@ -93,9 +93,68 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and export to Docker + uses: docker/build-push-action@v6 + with: + load: true + context: ${{ matrix.context }} + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha,scope=${{ matrix.image_name }} + cache-to: type=gha,mode=max,scope=${{ matrix.image_name }} + + # Following four steps are specifically for running automated tests which includes loading the + # mqtt-server image from the GitHub Actions Cache so that the docker compose automated tests can + # use this already built image instead of pulling it from GitHub Container Registry + # Note: These steps are only for the mqtt-server and the manager images and not for the nodered image. + # This is because, currently, docker-compose.automated-tests.yml uses only these two images for running automated tests. + - name: Save Docker image + if: ${{ matrix.image_name == 'mqtt-server' }} + id: save-mqtt-image + shell: bash + run: | + echo "TAG=${{ steps.docker-image-version-check.outputs.TAG }}" + docker save --output /tmp/mqtt-server_${{ steps.docker-image-version-check.outputs.TAG }}.tar ghcr.io/everest/everest-demo/mqtt-server:${{ steps.docker-image-version-check.outputs.TAG }} + + - name: Upload mqtt-server image as Artifact + if: ${{ matrix.image_name == 'mqtt-server' }} + uses: actions/upload-artifact@v4 + with: + name: mqtt_server_image_${{ steps.docker-image-version-check.outputs.TAG }} + path: /tmp/mqtt-server_${{ steps.docker-image-version-check.outputs.TAG }}.tar + overwrite: true + + - name: Download mqtt-server image as Artifact + if: ${{ matrix.image_name == 'manager' }} + uses: actions/download-artifact@v4 + with: + name: mqtt_server_image_${{ steps.docker-image-version-check.outputs.TAG }} + path: /tmp + + - name: Load Docker image + if: ${{ matrix.image_name == 'manager' }} + id: load-mqtt-image + shell: bash + run: | + docker load --input /tmp/mqtt-server_${{ steps.docker-image-version-check.outputs.TAG }}.tar + + - name: Run automated tests using docker-compose.automated-tests.yml + if: ${{ matrix.image_name == 'manager' }} + run: | + docker images + echo "Running docker compose up..." + docker compose --project-name everest-ac-automated-testing \ + --file "docker-compose.automated-tests.yml" up \ + --abort-on-container-exit \ + --exit-code-from manager + exit_code=$? + echo "Docker-compose up exit code from manager service: $exit_code" + - name: Build and push - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: ${{ matrix.context }} push: ${{ github.event_name != 'pull_request' }} diff --git a/manager/Dockerfile b/manager/Dockerfile index b1605f25..36821a56 100644 --- a/manager/Dockerfile +++ b/manager/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=linux/x86_64 ghcr.io/everest/build-kit-alpine:latest +FROM --platform=linux/x86_64 ghcr.io/everest/build-kit-alpine@sha256:7494bd6624aee3f882b4f1edbc589879e1d6d0ccc2c58f3f5c87ac1838ccd1de ARG EVEREST_VERSION=2024.3.0 ENV EVEREST_VERSION=${EVEREST_VERSION}