Skip to content

Commit

Permalink
Latest fixes to ensure image built locally and tests run on that imag…
Browse files Browse the repository at this point in the history
…e + Added exit_code

Docker compose should now use locally built image.
Problem was with ${DEMO_DIR}. Directly using docker file name works: ${DEMO_COMPOSE_FILE_NAME}.

Also added exit_code and abort-container so that the docker compose up command exits whenever any one container exits. In our testing case, when manager container exits.

Signed-off-by: Mahadik, Mukul Chandrakant <[email protected]>
  • Loading branch information
Mahadik, Mukul Chandrakant authored and Mahadik, Mukul Chandrakant committed Jul 3, 2024
1 parent cdf249d commit c3bba26
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 95 deletions.
187 changes: 93 additions & 94 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
name: cicd

on:
# TODO: Remove [automate-tests-actions, automate-tests-merge] branch once changes are final
pull_request:
branches: [ main, automate-tests-merge ]
branches: [ main ]
push:
branches: [ main, automate-tests-actions, automate-tests-merge ]
branches: [ main ]
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
run-demo-automated-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: List Docker images
run: docker images

- name: Run automated test script
timeout-minutes: 30
run: |
bash demo-automated-testing.sh
- name: List Docker images
run: docker images

docker-build-and-push-images:
needs: [run-demo-automated-tests]
runs-on: ubuntu-latest

permissions:
Expand All @@ -31,95 +51,74 @@ jobs:
context: ./nodered

steps:
- name: Temporary step to pass the job
id: temporary-step
run: echo "Temporary step to ensure job completes and workflow doesn't fail"

# - name: Checkout
# uses: actions/checkout@v4
# with:
# fetch-depth: 0

# - name: Ensure Docker image version is not referencing an existing release
# id: docker-image-version-check
# shell: bash
# run: |
# if ! [[ -s '.env' ]]; then
# echo 'Error: No .env file found.'
# exit 1
# fi

# if ! grep -qE '^TAG=' .env; then
# echo 'Error: .env must contain a TAG variable.'
# exit 1
# fi

# source .env

# # Fail if any previous Docker image version value matches the one in
# # this PR (excluding the current image version).
# for commit in $(git --no-pager log --first-parent --format=%H -- .env | tail -n +2); do
# if git --no-pager grep -hF "${TAG}" $commit -- .env | grep -qx ${TAG}; then
# echo 'Error: The version in .env matches an'
# echo ' earlier version on main. Please update the value in'
# echo ' .env to a new version.'
# exit 1
# fi
# done

# if git show-ref --tags --verify --quiet "refs/tags/v${TAG}"; then
# echo "Error: The tag 'v${TAG}' is already a GitHub release."
# echo ' Please update the version in .env'
# exit 1
# else
# echo "TAG=${TAG}" >> "${GITHUB_OUTPUT}"
# fi

# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3

# - name: Set Docker image metadata
# id: meta
# uses: docker/metadata-action@v5
# with:
# images: ${{ matrix.host_namespace }}/${{ matrix.image_name }}
# tags: |
# type=semver,pattern={{version}},value=v${{ steps.docker-image-version-check.outputs.TAG }}

# - name: Log into GitHub container registry
# if: github.event_name != 'pull_request'
# uses: docker/login-action@v3
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - name: Build and push
# uses: docker/build-push-action@v5
# with:
# context: ${{ matrix.context }}
# push: ${{ github.event_name != 'pull_request' }}
# 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 }}

dispatch:
needs: docker-build-and-push-images
runs-on: ubuntu-latest

steps:

- name: Trigger e2etest workflow
# TODO: Change repo owner from MukuFlash03 to EVerest; branch ref to main; once changes are final
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Ensure Docker image version is not referencing an existing release
id: docker-image-version-check
shell: bash
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/MukuFlash03/everest-demo/actions/workflows/e2etest.yaml/dispatches \
-d '{"ref":"automate-tests-actions", "inputs": {"parent_workflow": "cicd.yaml", "event_name": "${{ github.event_name }}" }}'
if ! [[ -s '.env' ]]; then
echo 'Error: No .env file found.'
exit 1
fi
if ! grep -qE '^TAG=' .env; then
echo 'Error: .env must contain a TAG variable.'
exit 1
fi
source .env
# Fail if any previous Docker image version value matches the one in
# this PR (excluding the current image version).
for commit in $(git --no-pager log --first-parent --format=%H -- .env | tail -n +2); do
if git --no-pager grep -hF "${TAG}" $commit -- .env | grep -qx ${TAG}; then
echo 'Error: The version in .env matches an'
echo ' earlier version on main. Please update the value in'
echo ' .env to a new version.'
exit 1
fi
done
if git show-ref --tags --verify --quiet "refs/tags/v${TAG}"; then
echo "Error: The tag 'v${TAG}' is already a GitHub release."
echo ' Please update the version in .env'
exit 1
else
echo "TAG=${TAG}" >> "${GITHUB_OUTPUT}"
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set Docker image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.host_namespace }}/${{ matrix.image_name }}
tags: |
type=semver,pattern={{version}},value=v${{ steps.docker-image-version-check.outputs.TAG }}
- name: Log into GitHub container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context }}
push: ${{ github.event_name != 'pull_request' }}
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 }}
15 changes: 14 additions & 1 deletion demo-automated-testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,18 @@ download_demo_file() {
download_demo_file "${DEMO_COMPOSE_FILE_NAME}"
download_demo_file .env

echo "Running docker compose up..."
docker compose --project-name everest-ac-demo \
--file "${DEMO_DIR}/${DEMO_COMPOSE_FILE_NAME}" up
--file "${DEMO_COMPOSE_FILE_NAME}" up \
--build \
--abort-on-container-exit \
--exit-code-from manager

exit_code=$?
echo "Docker-compose up exit code from manager service: $exit_code"

echo "Running docker compose down..."
docker compose --project-name everest-ac-demo \
--file "${DEMO_COMPOSE_FILE_NAME}" down

exit $exit_code
4 changes: 4 additions & 0 deletions docker-compose.automated-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ version: "3.6"
services:
mqtt-server:
image: ghcr.io/everest/everest-demo/mqtt-server:${TAG}
build: mosquitto
pull_policy: build
logging:
driver: none

manager:
image: ghcr.io/everest/everest-demo/manager:${TAG}
build: manager
pull_policy: build
depends_on:
- mqtt-server
environment:
Expand Down

0 comments on commit c3bba26

Please sign in to comment.