diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7a7df22..7eb347c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,10 +14,10 @@ cache: paths: - .cache/pip +# This job tests if the book compiles gracefully after a new addition test-build: stage: test - tags: - - Textbook runner + image: continuumio/miniconda3 rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" script: @@ -25,10 +25,10 @@ test-build: - jupyter-book clean book/ - jupyter-book build book/ +# This job builds the Docker container build-book: stage: build - tags: - - Textbook runner + image: docker rules: - if: $CI_COMMIT_BRANCH == "publish" && $CI_PIPELINE_SOURCE == "push" variables: @@ -36,38 +36,41 @@ build-book: - if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push" variables: TAG: $TAG_DRAFT + before_script: + - docker info script: - if [ "$TAG" = "$TAG_LATEST" ]; then sed --in-place=".bak" '/# START DRAFT/,/# END DRAFT/{//!d}' book/_config.yml; fi - # You might need to adjust or remove these Docker commands depending on the runner's capabilities - docker build -t $TAG . - docker push $TAG +# This job takes down the existing container and starts the new one deploy-book: stage: deploy - tags: - - Textbook runner + image: docker rules: - if: $CI_COMMIT_BRANCH == "publish" && $CI_PIPELINE_SOURCE == "push" + before_script: + - docker info + - docker stop $CI_PROJECT_NAME || exit_code=$? + - if [ $exit_code -ne 0 ]; then echo "Container not found, cannot stop"; else docker rm $CI_PROJECT_NAME; fi script: - # These Docker commands might need to be adjusted or replaced - - docker stop $CI_PROJECT_NAME || true - - docker rm $CI_PROJECT_NAME || true - - docker run -d --restart always -p 8000:8000 --name $CI_PROJECT_NAME $TAG_LATEST + - docker run -d --restart always -p 8000:8000 --name $CI_PROJECT_NAME $TAG_LATEST # Make sure to use a different port for each book! environment: name: production url: https://interactivetextbooks.citg.tudelft.nl/jupyter-book-manual +# Deploy the draft version of the book deploy-draft: stage: deploy - tags: - - Textbook runner + image: docker rules: - if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push" + before_script: + - docker info + - docker stop $CI_PROJECT_NAME-draft || exit_code=$? + - if [ $exit_code -ne 0 ]; then echo "Container not found, cannot stop"; else docker rm $CI_PROJECT_NAME-draft; fi script: - # These Docker commands might need to be adjusted or replaced - - docker stop $CI_PROJECT_NAME-draft || true - - docker rm $CI_PROJECT_NAME-draft || true - docker run -d --restart always -p 8018:8000 --name $CI_PROJECT_NAME-draft $TAG_DRAFT environment: name: draft - url: https://interactivetextbooks.citg.tudelft.nl/jupyter-book-manual-draft \ No newline at end of file + url: https://interactivetextbooks.citg.tudelft.nl/jupyter-book-manual-draft