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

Issue712 service deployment 2 #724

Merged
merged 10 commits into from
Jan 14, 2025
Next Next commit
add ci to build and test service containers
tijcolem committed Dec 26, 2024
commit f5e2310309ce16943851d86b081238d7896cce55
96 changes: 96 additions & 0 deletions .github/workflows/build_test_containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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: |
cd service
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
cd boptest && 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

#------------------------- Push to GitHub registry (disabled) -----------------------------
#
# - name: Log in to the GitHub container registry
# uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# 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: 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: ci/publish_to_docker.sh
32 changes: 32 additions & 0 deletions ci/publish_to_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# load .env defines in root of repo
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

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}"
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

docker image ls
docker tag ${WEB_REGISTRY_URI}:latest ${DOCKER_HUB_WEB_REGISTRY_URI}:${VERSION_TAG}; (( exit_status = exit_status || $? ))
docker tag ${WORKER_REGISTRY_URI}:latest ${DOCKER_HUB_WORKER_REGISTRY_URI}:${VERSION_TAG}; (( exit_status = exit_status || $? ))

echo "pushing ${DOCKER_HUB_WEB_REGISTRY_URI}:${VERSION_TAG}"
docker push ${DOCKER_HUB_WEB_REGISTRY_URI}:${VERSION_TAG}; (( exit_status = exit_status || $? ))
echo "pushing ${DOCKER_HUB_WORKER_REGISTRY_URI}:${VERSION_TAG}"
docker push ${DOCKER_HUB_WORKER_REGISTRY_URI}:${VERSION_TAG}; (( exit_status = exit_status || $? ))

fi

exit $exit_status
29 changes: 29 additions & 0 deletions ci/publish_to_github.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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

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"
fi

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

docker tag ${WEB_REGISTRY_URI}:latest ${GITHUB_WEB_REGISTRY_URI}:${VERSION_TAG}; (( exit_status = exit_status || $? ))
docker tag ${WORKER_REGISTRY_URI}:latest ${GITHUB_WORKER_REGISTRY_URI}:${VERSION_TAG}; (( exit_status = exit_status || $? ))

echo "pushing ${GITHUB_WEB_REGISTRY_URI}:${VERSION_TAG}"
docker push ${GITHUB_WEB_REGISTRY_URI}:${VERSION_TAG}; (( exit_status = exit_status || $? ))
echo "pushing ${GITHUB_WORKER_REGISTRY_URI}:${VERSION_TAG}"
docker push ${GITHUB_WORKER_REGISTRY_URI}:${VERSION_TAG}; (( exit_status = exit_status || $? ))

fi

exit $exit_status