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

Simplify the current CI/CD workflow #10

Merged
merged 14 commits into from
Dec 5, 2023
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TAG=0.0.3
69 changes: 58 additions & 11 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: cicd

on:
pull_request:
branches:
- main
push:
branches:
- 'build_pkg_**'
- main
tags:
- 'v*'
pull_request:
branches:
- 'main'
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
docker-build-and-push-images:
Expand All @@ -21,27 +21,72 @@ jobs:
strategy:
matrix:
include:
- image: ghcr.io/us-joet/everest-demo/manager
- host_namespace: ghcr.io/everest/everest-demo
image_name: manager
context: ./manager
- image: ghcr.io/us-joet/everest-demo/mqtt-server
- host_namespace: ghcr.io/everest/everest-demo
image_name: mqtt-server
context: ./mosquitto
- image: ghcr.io/us-joet/everest-demo/nodered
- host_namespace: ghcr.io/everest/everest-demo
image_name: nodered
context: ./nodered

steps:
- 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.image }}
images: ${{ matrix.host_namespace }}/${{ matrix.image_name }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern=${{ steps.docker-image-version-check.outputs.TAG }}

- name: Log into GitHub container registry
if: github.event_name != 'pull_request'
Expand All @@ -58,3 +103,5 @@ jobs:
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 }}
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ The use cases supported by the three demos are summarized in conceptual block di

### STEP 1: Run the demo
- Copy and paste the command for the demo you want to see:
- 🚨simple AC charging station ⚡: `curl -o docker-compose.yml https://raw.githubusercontent.com/everest/everest-demo/main/docker-compose.yml && docker compose -p everest up`
- 🚨ISO 15118 DC charging ⚡: `curl -o docker-compose.yml https://raw.githubusercontent.com/everest/everest-demo/main/docker-compose.iso15118-dc.yml && docker compose -p everest-dc up`
- 🚨 two EVSE charging ⚡: `curl -o docker-compose.yml https://raw.githubusercontent.com/everest/everest-demo/main/docker-compose.two-evse.yml && docker compose -p everest-two-evse up`
- 🚨 AC Charging ⚡: `curl https://raw.githubusercontent.com/everest/everest-demo/main/demo-ac.sh | bash`
- 🚨 ISO 15118 DC Charging ⚡: `curl https://raw.githubusercontent.com/everest/everest-demo/main/demo-iso15118-2-dc.sh | bash`
- 🚨 Two EVSE Charging ⚡: `curl https://raw.githubusercontent.com/everest/everest-demo/main/demo-two-evse.sh | bash`

### STEP 2: Interact with the demo
- Open the `nodered` flows to understand the module flows at http://127.0.0.1:1880
Expand All @@ -75,3 +75,6 @@ where `[prefix]` is `everest, everest-dc, everest-two-evse...`
## High level block diagram overview of EVerest capabilities
From https://everest.github.io/nightly/general/01_framework.html
![image](https://everest.github.io/nightly/_images/quick-start-high-level-1.png)

## Notes for Demo Contributors
Docker images defined in this repository are built during pull requests, on merges to `main`, and on pushes of semantic version tags. The labels for newly-built images are determined by the `TAG` environment variable specified in the root level `.env` file in this repository. The value of `TAG` is also used throughout the demo `docker-compose.*.yml`.
34 changes: 34 additions & 0 deletions demo-ac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

DEMO_COMPOSE_FILE_NAME='docker-compose.yml'
DEMO_DIR="$(mktemp -d)"

delete_temporary_directory() { rm -rf "${DEMO_DIR}"; }
trap delete_temporary_directory EXIT

if [[ ! "${DEMO_DIR}" || ! -d "${DEMO_DIR}" ]]; then
echo 'Error: Failed to create a temporary directory for the demo.'
exit 1
fi

download_demo_file() {
local -r repo_file_path="$1"
local -r repo_raw_url='https://raw.githubusercontent.com/everest/everest-demo/main'
local -r destination_path="${DEMO_DIR}/${repo_file_path}"

mkdir -p "$(dirname ${destination_path})"
curl -s -o "${destination_path}" "${repo_raw_url}/${repo_file_path}"
if [[ "$?" != 0 ]]; then
echo "Error: Failed to retrieve \"${repo_file_path}\" from the demo"
echo 'repository. If this issue persists, please report this as an'
echo 'issue in the EVerest project:'
echo ' https://github.com/EVerest/EVerest/issues'
exit 1
fi
}

download_demo_file "${DEMO_COMPOSE_FILE_NAME}"
download_demo_file .env

docker compose --project-name everest-ac-demo \
--file "${DEMO_DIR}/${DEMO_COMPOSE_FILE_NAME}" up
34 changes: 34 additions & 0 deletions demo-admin-panel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

DEMO_COMPOSE_FILE_NAME='docker-compose.admin-panel.yml'
DEMO_DIR="$(mktemp -d)"

delete_temporary_directory() { rm -rf "${DEMO_DIR}"; }
trap delete_temporary_directory EXIT

if [[ ! "${DEMO_DIR}" || ! -d "${DEMO_DIR}" ]]; then
echo 'Error: Failed to create a temporary directory for the demo.'
exit 1
fi

download_demo_file() {
local -r repo_file_path="$1"
local -r repo_raw_url='https://raw.githubusercontent.com/everest/everest-demo/main'
local -r destination_path="${DEMO_DIR}/${repo_file_path}"

mkdir -p "$(dirname ${destination_path})"
curl -s -o "${destination_path}" "${repo_raw_url}/${repo_file_path}"
if [[ "$?" != 0 ]]; then
echo "Error: Failed to retrieve \"${repo_file_path}\" from the demo"
echo 'repository. If this issue persists, please report this as an'
echo 'issue in the EVerest project:'
echo ' https://github.com/EVerest/EVerest/issues'
exit 1
fi
}

download_demo_file "${DEMO_COMPOSE_FILE_NAME}"
download_demo_file .env

docker compose --project-name everest-ac-demo \
--file "${DEMO_DIR}/${DEMO_COMPOSE_FILE_NAME}" up
34 changes: 34 additions & 0 deletions demo-iso15118-2-dc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

DEMO_COMPOSE_FILE_NAME='docker-compose.iso15118-dc.yml'
DEMO_DIR="$(mktemp -d)"

delete_temporary_directory() { rm -rf "${DEMO_DIR}"; }
trap delete_temporary_directory EXIT

if [[ ! "${DEMO_DIR}" || ! -d "${DEMO_DIR}" ]]; then
echo 'Error: Failed to create a temporary directory for the demo.'
exit 1
fi

download_demo_file() {
local -r repo_file_path="$1"
local -r repo_raw_url='https://raw.githubusercontent.com/everest/everest-demo/main'
local -r destination_path="${DEMO_DIR}/${repo_file_path}"

mkdir -p "$(dirname ${destination_path})"
curl -s -o "${destination_path}" "${repo_raw_url}/${repo_file_path}"
if [[ "$?" != 0 ]]; then
echo "Error: Failed to retrieve \"${repo_file_path}\" from the demo"
echo 'repository. If this issue persists, please report this as an'
echo 'issue in the EVerest project:'
echo ' https://github.com/EVerest/EVerest/issues'
exit 1
fi
}

download_demo_file "${DEMO_COMPOSE_FILE_NAME}"
download_demo_file .env

docker compose --project-name everest-ac-demo \
--file "${DEMO_DIR}/${DEMO_COMPOSE_FILE_NAME}" up
34 changes: 34 additions & 0 deletions demo-two-evse.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

DEMO_COMPOSE_FILE_NAME='docker-compose.two-evse.yml'
DEMO_DIR="$(mktemp -d)"

delete_temporary_directory() { rm -rf "${DEMO_DIR}"; }
trap delete_temporary_directory EXIT

if [[ ! "${DEMO_DIR}" || ! -d "${DEMO_DIR}" ]]; then
echo 'Error: Failed to create a temporary directory for the demo.'
exit 1
fi

download_demo_file() {
local -r repo_file_path="$1"
local -r repo_raw_url='https://raw.githubusercontent.com/everest/everest-demo/main'
local -r destination_path="${DEMO_DIR}/${repo_file_path}"

mkdir -p "$(dirname ${destination_path})"
curl -s -o "${destination_path}" "${repo_raw_url}/${repo_file_path}"
if [[ "$?" != 0 ]]; then
echo "Error: Failed to retrieve \"${repo_file_path}\" from the demo"
echo 'repository. If this issue persists, please report this as an'
echo 'issue in the EVerest project:'
echo ' https://github.com/EVerest/EVerest/issues'
exit 1
fi
}

download_demo_file "${DEMO_COMPOSE_FILE_NAME}"
download_demo_file .env

docker compose --project-name everest-ac-demo \
--file "${DEMO_DIR}/${DEMO_COMPOSE_FILE_NAME}" up
4 changes: 2 additions & 2 deletions docker-compose.admin-panel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ version: "3.6"

services:
mqtt-server:
image: ghcr.io/shankari/everest-demo/mqtt-server:0.0.1
image: ghcr.io/everest/everest-demo/mqtt-server:${TAG}
logging:
driver: none

manager:
image: ghcr.io/shankari/everest-demo/manager:0.0.2
image: ghcr.io/everest/everest-demo/manager:${TAG}
depends_on:
- mqtt-server
environment:
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ version: "3.6"

services:
mqtt-server:
image: ghcr.io/shankari/everest-demo/mqtt-server:0.0.1
image: ghcr.io/everest/everest-demo/mqtt-server:${TAG}
build: mosquitto
logging:
driver: none

manager:
image: ghcr.io/shankari/everest-demo/manager:0.0.2
image: ghcr.io/everest/everest-demo/manager:${TAG}
build: manager
depends_on:
- mqtt-server
Expand All @@ -19,7 +19,7 @@ services:
- net.ipv6.conf.all.disable_ipv6=0

node-red:
image: ghcr.io/shankari/everest-demo/nodered:0.0.1
image: ghcr.io/everest/everest-demo/nodered:${TAG}
build: nodered
depends_on:
- mqtt-server
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.iso15118-dc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ version: "3.6"

services:
mqtt-server:
image: ghcr.io/shankari/everest-demo/mqtt-server:0.0.1
image: ghcr.io/everest/everest-demo/mqtt-server:${TAG}
logging:
driver: none
ports:
- 1883:1883

manager:
image: ghcr.io/shankari/everest-demo/manager:0.0.2
image: ghcr.io/everest/everest-demo/manager:${TAG}
depends_on:
- mqtt-server
environment:
Expand All @@ -19,7 +19,7 @@ services:
- net.ipv6.conf.all.disable_ipv6=0

node-red:
image: ghcr.io/shankari/everest-demo/nodered:0.0.1
image: ghcr.io/everest/everest-demo/nodered:${TAG}
depends_on:
- mqtt-server
environment:
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.two-evse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ version: "3.6"

services:
mqtt-server:
image: ghcr.io/shankari/everest-demo/mqtt-server:0.0.1
image: ghcr.io/everest/everest-demo/mqtt-server:${TAG}
logging:
driver: none

manager:
image: ghcr.io/shankari/everest-demo/manager:0.0.2
image: ghcr.io/everest/everest-demo/manager:${TAG}
depends_on:
- mqtt-server
environment:
Expand All @@ -17,7 +17,7 @@ services:
- net.ipv6.conf.all.disable_ipv6=0

node-red:
image: ghcr.io/shankari/everest-demo/nodered:0.0.1
image: ghcr.io/everest/everest-demo/nodered:${TAG}
depends_on:
- mqtt-server
environment:
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ version: "3.6"

services:
mqtt-server:
image: ghcr.io/shankari/everest-demo/mqtt-server:0.0.1
image: ghcr.io/everest/everest-demo/mqtt-server:${TAG}
logging:
driver: none

manager:
image: ghcr.io/shankari/everest-demo/manager:0.0.2
image: ghcr.io/everest/everest-demo/manager:${TAG}
depends_on:
- mqtt-server
environment:
Expand All @@ -17,7 +17,7 @@ services:
- net.ipv6.conf.all.disable_ipv6=0

node-red:
image: ghcr.io/shankari/everest-demo/nodered:0.0.1
image: ghcr.io/everest/everest-demo/nodered:${TAG}
depends_on:
- mqtt-server
environment:
Expand Down
2 changes: 1 addition & 1 deletion manager/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ RUN git clone https://github.com/EVerest/everest-core.git \
# Copy over the custom config *after* the compile
COPY config-docker.json ./dist/share/everest/modules/OCPP/config-docker.json

LABEL org.opencontainers.image.source=https://github.com/us-joet/everest-demo
LABEL org.opencontainers.image.source=https://github.com/everest/everest-demo
2 changes: 1 addition & 1 deletion mosquitto/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM eclipse-mosquitto:2.0.10

COPY mosquitto.conf /mosquitto/config/mosquitto.conf

LABEL org.opencontainers.image.source=https://github.com/shankari/everest-demo
LABEL org.opencontainers.image.source=https://github.com/everest/everest-demo
2 changes: 1 addition & 1 deletion nodered/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ RUN npm install node-red-contrib-ui-level

COPY config /config

LABEL org.opencontainers.image.source=https://github.com/shankari/everest-demo
LABEL org.opencontainers.image.source=https://github.com/everest/everest-demo