diff --git a/.docs/build-website.sh b/.docs/build-website.sh index f235371f88fa8d3dbff6188745abf3934ce5137b..a8498bbd34517e60651066989b4181b1e8adb88b 100755 --- a/.docs/build-website.sh +++ b/.docs/build-website.sh @@ -4,16 +4,18 @@ function generate_docs { echo "===================================================" echo "Building DOCS for version $1 on branch $2" echo "===================================================" - git checkout "$2" - pip install -r ./requirements.txt + git reset --hard && git checkout "$2" + pip install -r ./requirements.txt > /dev/null mkdir -p ./final - if [ "$1" = "latest" ]; then - sed -i -e "s/__APPVERSION__/${APP_VERSION}/g" .docs/redirect.html - cp ./.docs/redirect.html ./final/index.html - fi find .docs/ -type f -exec sed -i -e "s/__APPVERSION__/$1/g" {} \; find .docs/ -type f -exec sed -i -e "s/__CHARTVERSION__/$1/g" {} \; - mkdocs build && cp -r ./site "./final/$1" + if [ "$1" = "latest" ]; then + INDEX_HTML=$(cat .docs/redirect.html) + OVERRIDES_MAIN_HTML=$(cat .docs/overrides/main.html) + else + echo $OVERRIDES_MAIN_HTML > .docs/overrides/main.html + fi + mkdocs build > /dev/null && cp -r ./site "./final/$1" cp -r "./swagger/$1" "./final/$1/swagger" } @@ -21,13 +23,16 @@ function generate_api { echo "===================================================" echo "Building API for version $1 on branch $2" echo "===================================================" - git checkout "$2" + git reset --hard && git checkout "$2" bash .docs/.swagger/swagger-site.sh find ./site -type f -exec sed -i -e "s/__APPVERSION__/$1/g" {} \; mkdir -p "./swagger/$1" cp -r ./site/* "./swagger/$1/" } +INDEX_HTML="" +OVERRIDES_MAIN_HTML="" + # usage if [ -z "$v1_TAGS" ]; then echo "Variable v1_TAGS not set" @@ -41,22 +46,32 @@ if [ -z "$APP_VERSION" ]; then exit 2 fi echo "APP_VERSION=$APP_VERSION" + + +echo " ~> latest" for i in "${!tags[@]}"; do version="${tags[i]}" echo " ~> $version" done -echo " ~> latest" # ensure branches exist on machine git fetch -# tags +# latest +generate_api "latest" "master" +generate_docs "latest" "master" + +# versions for i in "${!tags[@]}"; do version="${tags[i]}" generate_api "$version" "v$version" generate_docs "$version" "v$version" done -# master -generate_api "latest" "master" -generate_docs "latest" "master" +# finalization +echo "===================================================" +echo "Adding index.html from branch master" +echo $INDEX_HTML > .docs/redirect.html +sed -i -e "s/__APPVERSION__/${APP_VERSION}/g" .docs/redirect.html +cp ./.docs/redirect.html ./final/index.html +echo "===================================================" \ No newline at end of file diff --git a/.docs/overrides/main.html b/.docs/overrides/main.html index db14ec6adb627a5103d84d7cefc2411d52fe7d1f..033bce3aa3fb40911f955cfd35f949e27b24b6b2 100644 --- a/.docs/overrides/main.html +++ b/.docs/overrides/main.html @@ -2,26 +2,25 @@ {% block announce %} <label for="version">Version</label> -<select style="margin-left:8px;" id="version" name="version" onchange="switchVersion(this.options[this.selectedIndex].value)"> - <option value="latest">latest</option> - <option value="1.4.1">1.4.1</option> - <option value="1.4.0">1.4.0</option> - <option value="1.3.0">1.3.0</option> -</select> -<script> +<script type="javascript"> function getVersion() { - const segments = location.pathname.split('/') - console.debug('segments', segments) + const segments = location.pathname.split('/'); if (segments.length >= 4) { - return segments[3] + return segments[3]; } else { - return '__APPVERSION__' + return '__APPVERSION__'; } } function switchVersion(value) { if (!value) { return } - this.location.href = location.protocol + '//' + location.host + '/infrastructures/dbrepo/' + value + '/' + this.location.href = location.protocol + '//' + location.host + '/infrastructures/dbrepo/' + value + '/'; } - document.getElementById("version").value = getVersion() + document.getElementById("version").value = getVersion(); </script> +<select style="margin-left:8px;" id="version" name="version" onchange="switchVersion(this.options[this.selectedIndex].value)"> + <option value="latest">latest</option> + <option value="1.4.1">1.4.1</option> + <option value="1.4.0">1.4.0</option> + <option value="1.3.0">1.3.0</option> +</select> {% endblock %} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3cd9d3da41955ae2c3a564acc8292ada4cf2fecb..30686cd7d8c500d6438cf43d60701fc5eba58330 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -719,7 +719,7 @@ docs-1.4.0: - release-v1.3 - release-v1.4 script: - - apt-get update && apt-get install -y git make sed wget + - apt-get update && apt-get install -y git - git fetch --tags && git checkout v1.4.0 - pip install -r ./requirements.txt - wget https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services/-/raw/dev/.docs/overrides/main.html -O .docs/overrides/main.html -q diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..07b6177bf9661a7be30fde7d851f7f55d8fe63e4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM python:3.11-slim as build + +WORKDIR /app + +ENV v1_TAGS="1.4.0,1.4.1" +ENV APP_VERSION="1.4.1" + +RUN apt-get update && apt-get install -y git + +COPY .git/ .git/ +COPY .docs/ .docs/ +COPY ./requirements.txt ./requirements.txt + +RUN bash .docs/build-website.sh + +FROM nginx as runtime + +WORKDIR /usr/share/nginx/html/infrastructures/dbrepo/ + +COPY --from=build /app/final /usr/share/nginx/html/infrastructures/dbrepo/ + +RUN rm -f ./index.html + +RUN pwd + +RUN ls -la \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1fb934e77561d750f9d7bff2b25dae1d8a79b8c9..ecaea0a80b264770df568b7372d2af188f41de8a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,13 @@ volumes: storage-service-data: services: + website: + restart: "no" + image: website + build: . + ports: + - 8000:80 + dbrepo-metadata-db: restart: "no" container_name: dbrepo-metadata-db