Skip to content

Commit

Permalink
Merge pull request #724 from ibpsa/issue712_serviceDeployment
Browse files Browse the repository at this point in the history
Testing publish of images to registry
  • Loading branch information
dhblum authored Jan 14, 2025
2 parents c337b68 + 5491136 commit 8eea7b9
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 7 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/build_test_containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Build, test and publish containers

on:
pull_request:
branches:
- '*'
push:
branches:
- '*'
tags:
- '*'

jobs:

simulation-tests:
name: Build containers and run boptest simulation tests
runs-on: ubuntu-22.04
timeout-minutes: 240
env:
COMPOSE_PROJECT_NAME: boptest_service
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: "3.9"

- name: Build and run stack
run: |
cd service
docker compose build
docker compose up -d web worker
- name: dump docker logs
uses: jwalton/gh-docker-logs@v1

- name: Upload test cases to minio
run: |
# The provision script will wait for the web service to be available,
# so there is no need for an external wait-for-it script
cd service
docker compose run --no-deps provision
curl http://localhost/testcases
- name: Run example
run: |
python --version
pip install requests matplotlib numpy pandas
PYTHONPATH=$GITHUB_WORKSPACE
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV
# Storing PYTHONPATH above doesn't work for python so setting it below at run
PYTHONPATH=$PWD python examples/python/testcase1.py
- name: Run tests
run: |
cd service
docker compose run --no-deps test
- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v1

- name: Log in to the GitHub container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ghcr.io
username: ${{ secrets.GH_USERNAME }}
password: ${{ secrets.GH_REGISTRY }}

- name: Publish docker images to GitHub Registry
if: |
github.ref == 'refs/heads/develop' ||
contains(github.ref, 'refs/tags')
shell: bash
run: service/ci/publish_to_github.sh

#------------------ Push to docker hub (disabled) -------------------------------------
#
# - name: Log in to Docker Hub
# uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
# with:
# username: ${{ secrets.DOCKER_USER }}
# password: ${{ secrets.DOCKER_PASS }}
#
# - name: Publish docker images to Docker Hub
# if: |
# github.ref == 'refs/heads/develop' ||
# github.ref == 'refs/heads/experimental' ||
# contains(github.ref, 'refs/tags')
# shell: bash
# run: service/ci/publish_to_docker.sh
5 changes: 3 additions & 2 deletions service/ci/publish_to_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
export $(egrep -v '^#' .env | xargs)
export WEB_REGISTRY_URI=boptest_service-web
export WORKER_REGISTRY_URI=boptest_service-worker
export DOCKER_HUB_WEB_REGISTRY_URI=nrel/boptest-web
export DOCKER_HUB_WORKER_REGISTRY_URI=nrel/boptest-worker
export DOCKER_ORG=nrel
export DOCKER_HUB_WEB_REGISTRY_URI=$DOCKER_ORG/boptest-web
export DOCKER_HUB_WORKER_REGISTRY_URI=$DOCKER_ORG/boptest-worker

if [[ "${GITHUB_REF}" == "refs/heads/develop" ]]; then
export VERSION_TAG="develop"
Expand Down
14 changes: 9 additions & 5 deletions service/ci/publish_to_github.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# load .env defines in root of repo
export $(egrep -v '^#' .env | xargs)
export GITHUB_WEB_REGISTRY_URI=ghcr.io/NREL/boptest-web
export GITHUB_WORKER_REGISTRY_URI=ghcr.io/NREL/boptest-worker
export WEB_REGISTRY_URI=boptest_service-web
export WORKER_REGISTRY_URI=boptest_service-worker
export GITHUB_ORG=ibpsa
export GITHUB_WEB_REGISTRY_URI=ghcr.io/$GITHUB_ORG/boptest-web
export GITHUB_WORKER_REGISTRY_URI=ghcr.io/$GITHUB_ORG/boptest-worker


if [[ "${GITHUB_REF}" == "refs/heads/develop" ]]; then
export VERSION_TAG="develop"
echo "The docker tag is set to: ${VERSION_TAG}"
elif [[ "${GITHUB_REF}" =~ ^refs/tags/v[0-9].* ]]; then
export VERSION_TAG="${GITHUB_REF/refs\/tags\//}"
echo "The docker tag is set to: ${VERSION_TAG}"
# use conditional below if you want to build a custom branch
# elif [[] "${GITHUB_REF}" == "refs/heads/boptest-service-custom" ]]; then
# export VERSION_TAG="experimental"
elif [[ "${GITHUB_REF}" == "refs/heads/experimental" ]]; then
export VERSION_TAG="experimental"
echo "The docker tag is set to: ${VERSION_TAG}"
fi

if [[ "${VERSION_TAG}" == "develop" ]] || [[ "${VERSION_TAG}" =~ ^v[0-9].* ]] || [[ "${VERSION_TAG}" == "experimental" ]] ; then
Expand Down

0 comments on commit 8eea7b9

Please sign in to comment.