diff --git a/.github/workflows/build_test_containers.yml b/.github/workflows/build_test_containers.yml new file mode 100644 index 000000000..a9bebe20c --- /dev/null +++ b/.github/workflows/build_test_containers.yml @@ -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 diff --git a/service/ci/publish_to_docker.sh b/service/ci/publish_to_docker.sh index 02357d13a..9feac85fb 100755 --- a/service/ci/publish_to_docker.sh +++ b/service/ci/publish_to_docker.sh @@ -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" diff --git a/service/ci/publish_to_github.sh b/service/ci/publish_to_github.sh index 792db8ea9..81abcbf47 100755 --- a/service/ci/publish_to_github.sh +++ b/service/ci/publish_to_github.sh @@ -1,7 +1,11 @@ # 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" @@ -9,9 +13,9 @@ if [[ "${GITHUB_REF}" == "refs/heads/develop" ]]; then 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