Skip to content

Commit

Permalink
Migrate to using a .env file for Docker image versions
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Moore <[email protected]>
  • Loading branch information
drmrd committed Dec 5, 2023
1 parent 846d4cf commit f6afe9f
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 32 deletions.
1 change: 0 additions & 1 deletion .docker_image_version

This file was deleted.

1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TAG=0.0.3
28 changes: 14 additions & 14 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,35 @@ jobs:
- name: Ensure Docker image version is not referencing an existing release
id: docker-image-version-check
run: |
if ! [[ -s .docker_image_version ]]; then
echo 'Error: No .docker_image_version file found.'
if ! [[ -s .env ]]; then
echo 'Error: No .env file found.'
exit 1
fi
if [[ $(sed '/^\s*$/d' .docker_image_version | wc -l) -ge 2 ]]; then
echo 'Error: .docker_image_version should contain only one line.'
if ! [[ grep -qE '^TAG=' .env ]]; then
echo 'Error: .env must contain a TAG variable.'
exit 1
fi
SEMVER="$(cat .docker_image_version)"
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 -- .docker_image_version | tail -n +2); do
if git --no-pager grep -hF "${SEMVER}" $commit -- .docker_image_version | grep -qx ${SEMVER}; then
echo 'Error: The version in .docker_image_version matches an'
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 ' .docker_image_version to a new version.'
echo ' .env to a new version.'
exit 1
fi
done
if git show-ref --tags --verify --quiet "refs/tags/v${SEMVER}"; then
echo "Error: The tag 'v${SEMVER}' is already a GitHub release.'
echo ' Please update the version in .docker_image_version'
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 "SEMVER=${SEMVER}" >> "${GITHUB_OUTPUT}"
echo "TAG=${TAG}" >> "${GITHUB_OUTPUT}"
fi
- name: Set Docker image metadata
Expand All @@ -79,7 +79,7 @@ jobs:
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern=${{ steps.docker-image-version-check.outputs.SEMVER }}
type=semver,pattern=${{ steps.docker-image-version-check.outputs.TAG }}
- name: Log into GitHub container registry
uses: docker/login-action@v3
Expand Down
6 changes: 3 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 Down
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/everest/everest-demo/mqtt-server:0.0.3
image: ghcr.io/everest/everest-demo/mqtt-server:${TAG}
logging:
driver: none

manager:
image: ghcr.io/everest/everest-demo/manager:0.0.3
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/everest/everest-demo/mqtt-server:0.0.3
image: ghcr.io/everest/everest-demo/mqtt-server:${TAG}
build: mosquitto
logging:
driver: none

manager:
image: ghcr.io/everest/everest-demo/manager:0.0.3
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/everest/everest-demo/nodered:0.0.3
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/everest/everest-demo/mqtt-server:0.0.3
image: ghcr.io/everest/everest-demo/mqtt-server:${TAG}
logging:
driver: none
ports:
- 1883:1883

manager:
image: ghcr.io/everest/everest-demo/manager:0.0.3
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/everest/everest-demo/nodered:0.0.3
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/everest/everest-demo/mqtt-server:0.0.3
image: ghcr.io/everest/everest-demo/mqtt-server:${TAG}
logging:
driver: none

manager:
image: ghcr.io/everest/everest-demo/manager:0.0.3
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/everest/everest-demo/nodered:0.0.3
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/everest/everest-demo/mqtt-server:0.0.3
image: ghcr.io/everest/everest-demo/mqtt-server:${TAG}
logging:
driver: none

manager:
image: ghcr.io/everest/everest-demo/manager:0.0.3
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/everest/everest-demo/nodered:0.0.3
image: ghcr.io/everest/everest-demo/nodered:${TAG}
depends_on:
- mqtt-server
environment:
Expand Down

0 comments on commit f6afe9f

Please sign in to comment.