From c972a5982efc2c3cdb1d16918d449d70e3e3e3d9 Mon Sep 17 00:00:00 2001 From: Frank Agerholm Date: Wed, 4 Dec 2024 21:02:06 +0100 Subject: [PATCH 1/5] Create Image-Tag from CI_COMMIT_REF_SLUG --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a5f09de..e5d1966 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,8 +37,8 @@ deploy: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY script: - docker pull $CI_REGISTRY_IMAGE:job-$CI_PIPELINE_ID - - docker tag $CI_REGISTRY_IMAGE:job-$CI_PIPELINE_ID $CI_REGISTRY_IMAGE:latest - - docker push $CI_REGISTRY_IMAGE:latest + - docker tag $CI_REGISTRY_IMAGE:job-$CI_PIPELINE_ID $CI_REGISTRY_IMAGE:${CI_COMMIT_REF_SLUG:-latest} + - docker push $CI_REGISTRY_IMAGE:${CI_COMMIT_REF_SLUG:-latest} include: - template: Security/SAST.gitlab-ci.yml - template: Security/Container-Scanning.gitlab-ci.yml From ce60b815c9d4097d59fee5e86b48cc07cb9adf40 Mon Sep 17 00:00:00 2001 From: Frank Agerholm Date: Wed, 4 Dec 2024 21:07:00 +0100 Subject: [PATCH 2/5] Add node- and npm-version output to test stage --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e5d1966..d3b6f8b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,6 +27,8 @@ test: stage: test image: "$CI_REGISTRY_IMAGE:job-$CI_PIPELINE_ID" script: + - node --version + - npm --version - python --version - nikola --version - pip --version @@ -38,6 +40,7 @@ deploy: script: - docker pull $CI_REGISTRY_IMAGE:job-$CI_PIPELINE_ID - docker tag $CI_REGISTRY_IMAGE:job-$CI_PIPELINE_ID $CI_REGISTRY_IMAGE:${CI_COMMIT_REF_SLUG:-latest} + - echo "deploying $CI_REGISTRY_IMAGE:${CI_COMMIT_REF_SLUG:-latest}" - docker push $CI_REGISTRY_IMAGE:${CI_COMMIT_REF_SLUG:-latest} include: - template: Security/SAST.gitlab-ci.yml From a85e2a090e1bd22d87ff8e98fa88f0fa9396b698 Mon Sep 17 00:00:00 2001 From: Frank Agerholm Date: Wed, 4 Dec 2024 21:09:55 +0100 Subject: [PATCH 3/5] Add nodejs and npm to image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 74bd758..561e2bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM docker.io/library/python:3.11-alpine -RUN apk --no-cache add sshpass openssh-client lftp; mkdir -p /opt/app +RUN apk --no-cache add sshpass openssh-client lftp nodejs npm; mkdir -p /opt/app WORKDIR /opt/app ADD requirements.txt /root/ ADD Dockerfile /root/ From ce035d918605f6402a62702c12086097bbc557cc Mon Sep 17 00:00:00 2001 From: Frank Agerholm Date: Wed, 4 Dec 2024 21:44:12 +0100 Subject: [PATCH 4/5] Add configuration-File support. --- README.md | 10 +++++++++ bin/build.sh | 57 +++++++++++++++++++++++++++++++++++++++++++-------- bin/deploy.sh | 16 +++++++++++++-- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 966be18..6e109e6 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,16 @@ This image is based on the python:3.11-alpine image and includes additional Python-packages for building nikola-sites. +## Configure your project + +Create a configuration file in your git-repo: `.deployment-helper` + +Configuration-Variables: + +* DEPLOY_HELPER_ENABLE_NIKOLA (default: true) +* DEPLOY_HELPER_ENABLE_NODE (default: false) +* DEPLOY_HELPER_CONTENT_DIR (default: "website/output") + ## lftp for sftp-Uploads This image includes `lftp` to upload files to a sftp-server and use diff --git a/bin/build.sh b/bin/build.sh index 727aa8f..d7f92e1 100644 --- a/bin/build.sh +++ b/bin/build.sh @@ -1,18 +1,59 @@ #!/bin/sh -if ! test -d website +# Default configurations: +DEPLOY_HELPER_ENABLE_NIKOLA=true +DEPLOY_HELPER_ENABLE_NODE=false + +if test -f .deployment-helper then - echo "Website directory not found" - exit 1 + # shellcheck source=/dev/null + . .deployment-helper fi -if ! command -v nikola >/dev/null 2>&1 + + +if $DEPLOY_HELPER_ENABLE_NODE then - echo "nikola command not found" - exit 1 + if ! command -v node >/dev/null 2>&1 + then + echo "node not found" 1>&2 + exit 1 + fi + if ! command -v npm >/dev/null 2>&1 + then + echo "npm not found" 1>&2 + exit 1 + fi + if ! test -d node + then + echo "Node directory not found" 1>&2 + exit 1 + fi + + cd node || { echo 'Directory "node" not found'; exit 1;} + if ! npm install + then + echo "Error installing node-dependencies" 1>&2 + exit 1 + fi + cd .. fi -cd website +if $DEPLOY_HELPER_ENABLE_NIKOLA +then + if ! test -d website + then + echo "Website directory not found" 1>&2 + exit 1 + fi -nikola build + if ! command -v nikola >/dev/null 2>&1 + then + echo "nikola command not found" 1>&2 + exit 1 + fi + cd website || { echo 'Directory "website" not found'; exit 1;} + nikola build + cd .. +fi exit "$?" diff --git a/bin/deploy.sh b/bin/deploy.sh index bdf78f1..154fa0f 100755 --- a/bin/deploy.sh +++ b/bin/deploy.sh @@ -1,7 +1,16 @@ #!/bin/sh +# Default configurations: +DEPLOY_HELPER_CONTENT_DIR="website/output" -if ! test -d website/output +if test -f .deployment-helper +then + # shellcheck source=/dev/null + . .deployment-helper +fi + + +if ! test -d "${DEPLOY_HELPER_CONTENT_DIR}" then echo "Website-Build not found" exit 1 @@ -16,6 +25,9 @@ then fi -lftp -e 'set sftp:auto-confirm yes; mirror -R ./website/output/ ./web/; bye' --env-password -u ${SSH_USER} sftp://${SSH_HOST} +lftp -e "set sftp:auto-confirm yes; mirror -R ${DEPLOY_HELPER_CONTENT_DIR} ./web/; bye" \ + --env-password \ + -u ${SSH_USER} \ + sftp://${SSH_HOST} From 9506e727addb1fb2b3be5dde50c837be61916230 Mon Sep 17 00:00:00 2001 From: Frank Agerholm Date: Wed, 4 Dec 2024 22:35:12 +0100 Subject: [PATCH 5/5] Build for nuxi based Websites --- bin/build.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bin/build.sh b/bin/build.sh index d7f92e1..9311cd3 100644 --- a/bin/build.sh +++ b/bin/build.sh @@ -36,6 +36,23 @@ then echo "Error installing node-dependencies" 1>&2 exit 1 fi + if test -f nuxt.config.ts + then + # Build for nuxi based Sites + if ! npx nuxi build + then + echo "Error nuxi build" 1>&2 + exit 1 + fi + if ! npx nuxi generate + then + echo "Error nuxi generate" 1>&2 + exit 1 + fi + else + echo "No supportet node website type found" 1>&2 + exit 1 + fi cd .. fi