diff --git a/.docs/build-website.sh b/.docs/build-website.sh index f235371f88fa8d3dbff6188745abf3934ce5137b..b6c366d9331381dd2e979cbbae04191975a5ed5f 100755 --- a/.docs/build-website.sh +++ b/.docs/build-website.sh @@ -1,27 +1,37 @@ #!/bin/bash +OVERRIDES_MAIN_HTML="" +SCRIPTS_EXTRA_JS="" + function generate_docs { + BRANCH="release-$1" echo "===================================================" - echo "Building DOCS for version $1 on branch $2" + echo "Building DOCS for version $1 on branch $BRANCH" echo "===================================================" - git checkout "$2" - pip install -r ./requirements.txt + git reset --hard && git checkout "$BRANCH" + 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 + OVERRIDES_MAIN_HTML=$(cat .docs/overrides/main.html) + sed -i -e "s/__APPVERSION__/${APP_VERSION}/g" .docs/scripts/extra.js + SCRIPTS_EXTRA_JS=$(cat .docs/scripts/extra.js) + else + echo $OVERRIDES_MAIN_HTML > .docs/overrides/main.html + mkdir -p .docs/scripts + echo $SCRIPTS_EXTRA_JS > .docs/scripts/extra.js 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" + mkdocs build > /dev/null && cp -r ./site "./final/$1" cp -r "./swagger/$1" "./final/$1/swagger" } function generate_api { + BRANCH="release-$1" echo "===================================================" - echo "Building API for version $1 on branch $2" + echo "Building API for version $1 on branch $BRANCH" echo "===================================================" - git checkout "$2" + git reset --hard && git checkout "$BRANCH" bash .docs/.swagger/swagger-site.sh find ./site -type f -exec sed -i -e "s/__APPVERSION__/$1/g" {} \; mkdir -p "./swagger/$1" @@ -29,34 +39,37 @@ function generate_api { } # usage -if [ -z "$v1_TAGS" ]; then - echo "Variable v1_TAGS not set" +if [ -z "$VERSIONS" ]; then + echo "Variable VERSIONS not set" exit 1 fi -tags=(${v1_TAGS//,/ }) +versions=(${VERSIONS//,/ }) # usage if [ -z "$APP_VERSION" ]; then echo "Variable APP_VERSION not set" exit 2 fi +echo "===================================================" echo "APP_VERSION=$APP_VERSION" -for i in "${!tags[@]}"; do - version="${tags[i]}" - echo " ~> $version" -done -echo " ~> latest" +echo "===================================================" # ensure branches exist on machine git fetch -# tags -for i in "${!tags[@]}"; do - version="${tags[i]}" - generate_api "$version" "v$version" - generate_docs "$version" "v$version" +generate_api "latest" +generate_docs "latest" + +# versions +for i in "${!versions[@]}"; do + version="${versions[i]}" + generate_api "$version" + generate_docs "$version" done -# master -generate_api "latest" "master" -generate_docs "latest" "master" + +# finalization +echo "===================================================" +echo "Moving default version $APP_VERSION docs to /" +cp -r ./final/${APP_VERSION}/* ./final/ +echo "===================================================" diff --git a/.docs/redirect.html b/.docs/redirect.html index 053a5581bfeeb797c2d571a1dd378b1ed88df305..a3737a67b6655b56c4c31f35f8bfc279a72b5e0f 100644 --- a/.docs/redirect.html +++ b/.docs/redirect.html @@ -5,7 +5,7 @@ <head> <meta charset="UTF-8"> <title>Redirect Notice</title> - <meta http-equiv="Refresh" content="0; url='https://www.ifs.tuwien.ac.at/infrastructures/dbrepo/__APPVERSION__/'" /> + <meta http-equiv="Refresh" content="0; url='/infrastructures/dbrepo/__APPVERSION__/'" /> </head> <body> <h1>Redirect Notice</h1> @@ -14,7 +14,7 @@ available at: </p> <p> - <a href="https://www.ifs.tuwien.ac.at/infrastructures/dbrepo/__APPVERSION__/">https://www.ifs.tuwien.ac.at/infrastructures/dbrepo/__APPVERSION__/</a> + <a href="/infrastructures/dbrepo/__APPVERSION__/">/infrastructures/dbrepo/__APPVERSION__/</a> </p> </body> </html> \ No newline at end of file diff --git a/.docs/scripts/extra.js b/.docs/scripts/extra.js index 4768615e22f22fc7f895cfee742ed9c848347b89..b5ae3d0a12749d5e825a396f96d67e8e51e3fcaa 100644 --- a/.docs/scripts/extra.js +++ b/.docs/scripts/extra.js @@ -1,8 +1,10 @@ function getVersion() { const segments = location.pathname.split('/'); - if (segments.length >= 4) { + if (segments.length > 4) { + console.debug('version', segments[3]); return segments[3]; } else { + console.debug('default version', '__APPVERSION__'); return '__APPVERSION__'; } } 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..0030985143799d899b4a6a5feaf7878f8ec506ce --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.11-slim as build + +WORKDIR /app + +RUN apt-get update && apt-get install -y git + +ENV VERSIONS="1.4.1,1.4.0,1.3.0" +ENV APP_VERSION="1.4.1" + +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/ \ 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