Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes from previous PR on Running automated tests via CICD #67

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 63 additions & 4 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Comment on lines +114 to +117
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we not have to save the node-red container as well? I guess since this is an automated test, maybe not. Can you please add a comment here to clarify?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment.

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' }}
Expand Down
2 changes: 1 addition & 1 deletion manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -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}
Expand Down