From ff7a18cabebba22e7e4a74881368bdb39322b958 Mon Sep 17 00:00:00 2001 From: Mirco Date: Fri, 13 Oct 2023 15:44:20 +0200 Subject: [PATCH] Updated c4k-forgejo --- .gitlab-ci.yml | 108 +++++------ build.py | 181 ++++++++++++++---- .../{docker-backup => backup}/build.py | 26 ++- .../image/Dockerfile | 0 .../image/resources/backup.sh | 0 .../resources/entrypoint-start-and-wait.sh | 0 .../image/resources/entrypoint.sh | 0 .../image/resources/init.sh | 0 .../image/resources/install.sh | 0 .../image/resources/restic-snapshots.sh | 0 .../image/resources/restore.sh | 0 .../{docker-backup => backup}/test/Dockerfile | 0 .../test/serverspec.edn | 0 .../{docker-federated => federated}/build.py | 26 ++- .../image/Dockerfile | 0 .../test/Dockerfile | 0 .../test/serverspec.edn | 0 17 files changed, 227 insertions(+), 114 deletions(-) rename infrastructure/{docker-backup => backup}/build.py (70%) rename infrastructure/{docker-backup => backup}/image/Dockerfile (100%) rename infrastructure/{docker-backup => backup}/image/resources/backup.sh (100%) rename infrastructure/{docker-backup => backup}/image/resources/entrypoint-start-and-wait.sh (100%) rename infrastructure/{docker-backup => backup}/image/resources/entrypoint.sh (100%) rename infrastructure/{docker-backup => backup}/image/resources/init.sh (100%) rename infrastructure/{docker-backup => backup}/image/resources/install.sh (100%) rename infrastructure/{docker-backup => backup}/image/resources/restic-snapshots.sh (100%) rename infrastructure/{docker-backup => backup}/image/resources/restore.sh (100%) rename infrastructure/{docker-backup => backup}/test/Dockerfile (100%) rename infrastructure/{docker-backup => backup}/test/serverspec.edn (100%) rename infrastructure/{docker-federated => federated}/build.py (69%) rename infrastructure/{docker-federated => federated}/image/Dockerfile (100%) rename infrastructure/{docker-federated => federated}/test/Dockerfile (100%) rename infrastructure/{docker-federated => federated}/test/serverspec.edn (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 737420d..ae183ec 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,11 +5,18 @@ stages: - upload - image -services: - - docker:19.03.12-dind +.img: &img + image: "domaindrivenarchitecture/ddadevops-dind:4.7.2" + services: + - docker:dind + before_script: + - export RELEASE_ARTIFACT_TOKEN=$MEISSA_REPO_BUERO_RW + - export IMAGE_DOCKERHUB_USER=$DOCKERHUB_USER + - export IMAGE_DOCKERHUB_PASSWORD=$DOCKERHUB_PASSWORD + - export IMAGE_TAG=$CI_COMMIT_TAG .cljs-job: &cljs - image: domaindrivenarchitecture/shadow-cljs + image: "domaindrivenarchitecture/ddadevops-clj-cljs:4.7.2" cache: key: ${CI_COMMIT_REF_SLUG} paths: @@ -17,38 +24,44 @@ services: - .shadow-cljs/ - .m2 before_script: - - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc - - npm install + - export RELEASE_ARTIFACT_TOKEN=$MEISSA_REPO_BUERO_RW + - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc + - npm install -.clj-uploadjob: &clj - image: domaindrivenarchitecture/lein +.clj-job: &clj + image: "domaindrivenarchitecture/ddadevops-clj-cljs:4.7.2" cache: key: ${CI_COMMIT_REF_SLUG} paths: - .m2 before_script: - - mkdir -p /root/.lein - - echo "{:auth {:repository-auth {#\"clojars\" {:username \"${CLOJARS_USER}\" :password \"${CLOJARS_TOKEN_DOMAINDRIVENARCHITECTURE}\" }}}}" > ~/.lein/profiles.clj + - export RELEASE_ARTIFACT_TOKEN=$MEISSA_REPO_BUERO_RW + - mkdir -p /root/.lein + - echo "{:auth {:repository-auth {#\"clojars\" {:username \"${CLOJARS_USER}\" :password \"${CLOJARS_TOKEN_DOMAINDRIVENARCHITECTURE}\" }}}}" > ~/.lein/profiles.clj -test-cljs: - <<: *cljs - stage: build_and_test - script: - - shadow-cljs compile test - - node target/node-tests.js +.tag_only: &tag_only + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + when: never + - if: '$CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+\.[0-9]+$/' test-clj: <<: *clj stage: build_and_test script: - - lein test + - pyb test_clj + +test-cljs: + <<: *cljs + stage: build_and_test + script: + - pyb test_cljs test-schema: <<: *clj stage: build_and_test script: - - lein uberjar - - java -jar target/uberjar/c4k-forgejo-standalone.jar src/test/resources/forgejo-test/valid-config.yaml src/test/resources/forgejo-test/valid-auth.yaml | kubeconform --kubernetes-version 1.19.0 --strict --skip Certificate - + - pyb test_schema artifacts: paths: - target/uberjar @@ -57,8 +70,7 @@ report-frontend: <<: *cljs stage: package script: - - mkdir -p target/frontend-build - - shadow-cljs run shadow.cljs.build-report frontend target/frontend-build/build-report.html + - pyb report_frontend artifacts: paths: - target/frontend-build/build-report.html @@ -67,11 +79,7 @@ package-frontend: <<: *cljs stage: package script: - - mkdir -p target/frontend-build - - shadow-cljs release frontend - - cp public/js/main.js target/frontend-build/c4k-forgejo.js - - sha256sum target/frontend-build/c4k-forgejo.js > target/frontend-build/c4k-forgejo.js.sha256 - - sha512sum target/frontend-build/c4k-forgejo.js > target/frontend-build/c4k-forgejo.js.sha512 + - pyb package_frontend artifacts: paths: - target/frontend-build @@ -80,53 +88,35 @@ package-uberjar: <<: *clj stage: package script: - - lein uberjar - - sha256sum target/uberjar/c4k-forgejo-standalone.jar > target/uberjar/c4k-forgejo-standalone.jar.sha256 - - sha512sum target/uberjar/c4k-forgejo-standalone.jar > target/uberjar/c4k-forgejo-standalone.jar.sha512 + - pyb package_uberjar artifacts: paths: - target/uberjar -upload-clj-release: +release-to-clojars: <<: *clj + <<: *tag_only stage: upload - rules: - - if: '$CI_COMMIT_TAG != null' script: - - lein deploy + - pyb upload_clj -release: - image: registry.gitlab.com/gitlab-org/release-cli:latest +release-to-forgejo: + <<: *clj + <<: *tag_only stage: upload - rules: - - if: '$CI_COMMIT_TAG != null' - artifacts: - paths: - - target/uberjar - - target/frontend-build script: - - apk --no-cache add curl - - | - release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \ - --assets-link "{\"name\":\"c4k-forgejo-standalone.jar\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-forgejo/-/jobs/${CI_JOB_ID}/artifacts/file/target/uberjar/c4k-forgejo-standalone.jar\"}" \ - --assets-link "{\"name\":\"c4k-forgejo-standalone.jar.sha256\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-forgejo/-/jobs/${CI_JOB_ID}/artifacts/file/target/uberjar/c4k-forgejo-standalone.jar.sha256\"}" \ - --assets-link "{\"name\":\"c4k-forgejo-standalone.jar.sha512\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-forgejo/-/jobs/${CI_JOB_ID}/artifacts/file/target/uberjar/c4k-forgejo-standalone.jar.sha512\"}" \ - --assets-link "{\"name\":\"c4k-forgejo.js\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-forgejo/-/jobs/${CI_JOB_ID}/artifacts/file/target/frontend-build/c4k-forgejo.js\"}" \ - --assets-link "{\"name\":\"c4k-forgejo.js.sha256\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-forgejo/-/jobs/${CI_JOB_ID}/artifacts/file/target/frontend-build/c4k-forgejo.js.sha256\"}" \ - --assets-link "{\"name\":\"c4k-forgejo.js.sha512\",\"url\":\"https://gitlab.com/domaindrivenarchitecture/c4k-forgejo/-/jobs/${CI_JOB_ID}/artifacts/file/target/frontend-build/c4k-forgejo.js.sha512\"}" \ + - pyb publish_artifacts -forgejo-backup-image-test-publish: - image: domaindrivenarchitecture/devops-build:latest +forgejo-backup-image-publish: + <<: *img + <<: *tag_only stage: image - rules: - - if: '$CI_COMMIT_TAG != null' script: - - cd infrastructure/docker-backup && pyb image test publish + - cd infrastructure/backup && pyb image publish -forgejo-federated-image-test-publish: - image: domaindrivenarchitecture/devops-build:latest +forgejo-federated-image-publish: + <<: *img + <<: *tag_only stage: image - rules: - - if: '$CI_COMMIT_TAG != null' script: - - cd infrastructure/docker-federated && pyb image test publish \ No newline at end of file + - cd infrastructure/federated && pyb image publish \ No newline at end of file diff --git a/build.py b/build.py index de5d5da..06e1bb9 100644 --- a/build.py +++ b/build.py @@ -1,15 +1,16 @@ from os import environ from subprocess import run -from pybuilder.core import task, init +from pybuilder.core import init, task from ddadevops import * -name = 'c4k' -MODULE = 'forgejo' -PROJECT_ROOT_PATH = '..' +default_task = "dev" +name = 'c4k-forgejo' +MODULE = 'not-used' +PROJECT_ROOT_PATH = '.' @init def initialize(project): - project.build_depends_on("ddadevops>=4.0.0") + project.build_depends_on("ddadevops>=4.7.0") input = { "name": name, @@ -19,7 +20,18 @@ def initialize(project): "build_types": [], "mixin_types": ["RELEASE"], "release_primary_build_file": "project.clj", - "release_secondary_build_files": ["package.json"], + "release_secondary_build_files": [ + "package.json", + "infrastructure/backup/build.py", + "infrastructure/federated/build.py", + ], + "release_artifact_server_url": "https://repo.prod.meissa.de", + "release_organisation": "meissa", + "release_repository_name": name, + "release_artifacts": [ + "target/uberjar/c4k-forgejo-standalone.jar", + "target/frontend-build/c4k-forgejo.js", + ], } build = ReleaseMixin(project, input) @@ -27,48 +39,141 @@ def initialize(project): @task -def prepare_release(project): +def test_clj(project): + run("lein test", shell=True, check=True) + + +@task +def test_cljs(project): + run("shadow-cljs compile test", shell=True, check=True) + run("node target/node-tests.js", shell=True, check=True) + + +@task +def test_schema(project): + run("lein uberjar", shell=True, check=True) + run( + "java -jar target/uberjar/c4k-forgejo-standalone.jar " + + "src/test/resources/forgejo-test/valid-config.yaml " + + "src/test/resources/forgejo-test/valid-auth.yaml | " + + "kubeconform --kubernetes-version 1.23.0 --strict --skip Certificate -", + shell=True, + check=True, + ) + + +@task +def report_frontend(project): + run("mkdir -p target/frontend-build", shell=True, check=True) + run( + "shadow-cljs run shadow.cljs.build-report frontend target/frontend-build/build-report.html", + shell=True, + check=True, + ) + + +@task +def package_frontend(project): + run("mkdir -p target/frontend-build", shell=True, check=True) + run("shadow-cljs release frontend", shell=True, check=True) + run( + "cp public/js/main.js target/frontend-build/c4k-forgejo.js", + shell=True, + check=True, + ) + run( + "sha256sum target/frontend-build/c4k-forgejo.js > target/frontend-build/c4k-forgejo.js.sha256", + shell=True, + check=True, + ) + run( + "sha512sum target/frontend-build/c4k-forgejo.js > target/frontend-build/c4k-forgejo.js.sha512", + shell=True, + check=True, + ) + + +@task +def package_uberjar(project): + run( + "sha256sum target/uberjar/c4k-forgejo-standalone.jar > target/uberjar/c4k-forgejo-standalone.jar.sha256", + shell=True, + check=True, + ) + run( + "sha512sum target/uberjar/c4k-forgejo-standalone.jar > target/uberjar/c4k-forgejo-standalone.jar.sha512", + shell=True, + check=True, + ) + + +@task +def upload_clj(project): + run("lein deploy", shell=True, check=True) + + +@task +def lint(project): + run( + "lein eastwood", + shell=True, + check=True, + ) + run( + "lein ancient check", + shell=True, + check=True, + ) + + +@task +def patch(project): + linttest(project, "PATCH") + release(project) + + +@task +def minor(project): + linttest(project, "MINOR") + release(project) + + +@task +def major(project): + linttest(project, "MAJOR") + release(project) + + +@task +def dev(project): + linttest(project, "NONE") + + +@task +def prepare(project): build = get_devops_build(project) build.prepare_release() + @task -def tag_bump_and_push_release(project): +def tag(project): build = get_devops_build(project) build.tag_bump_and_push_release() @task -def patch(project): - build_all(project, "PATCH") +def publish_artifacts(project): + build = get_devops_build(project) + build.publish_artifacts() -@task -def minor(project): - build_all(project, "MINOR") +def release(project): + prepare(project) + tag(project) -@task -def major(project): - build_all(project, "MAJOR") - -@task -def dev(project): - build_all(project, "NONE") -@task -def test(project): - run("lein test", shell=True) - -@task -def build_it(project): - run("lein uberjar", shell=True) - -@task -def publish(project): - run("lein deploy", shell=True) - -def build_all(project, release_type): +def linttest(project, release_type): build = get_devops_build(project) build.update_release_type(release_type) - test(project) - prepare_release(project) - build_it(project) - tag_bump_and_push_release(project) - + test_clj(project) + test_cljs(project) + test_schema(project) + lint(project) diff --git a/infrastructure/docker-backup/build.py b/infrastructure/backup/build.py similarity index 70% rename from infrastructure/docker-backup/build.py rename to infrastructure/backup/build.py index 2247dd4..fcd8248 100644 --- a/infrastructure/docker-backup/build.py +++ b/infrastructure/backup/build.py @@ -1,14 +1,20 @@ from os import environ +from datetime import datetime from pybuilder.core import task, init from ddadevops import * -name = "c4k-forgejo-backup" -MODULE = "docker" +name = "c4k-forgejo" +MODULE = "backup" PROJECT_ROOT_PATH = "../.." +version = "3.0.4-SNAPSHOT" @init def initialize(project): + image_tag = version + if "dev" in image_tag: + image_tag += datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + input = { "name": name, "module": MODULE, @@ -16,9 +22,11 @@ def initialize(project): "project_root_path": PROJECT_ROOT_PATH, "build_types": ["IMAGE"], "mixin_types": [], + "image_naming": "NAME_AND_MODULE", + "image_tag": f"{image_tag}", } - project.build_depends_on("ddadevops>=4.0.0-dev") + project.build_depends_on("ddadevops>=4.7.0") build = DevopsImageBuild(project, input) build.initialize_build_dir() @@ -36,14 +44,14 @@ def drun(project): build.drun() +@task +def test(project): + build = get_devops_build(project) + build.test() + + @task def publish(project): build = get_devops_build(project) build.dockerhub_login() build.dockerhub_publish() - - -@task -def test(project): - build = get_devops_build(project) - build.test() diff --git a/infrastructure/docker-backup/image/Dockerfile b/infrastructure/backup/image/Dockerfile similarity index 100% rename from infrastructure/docker-backup/image/Dockerfile rename to infrastructure/backup/image/Dockerfile diff --git a/infrastructure/docker-backup/image/resources/backup.sh b/infrastructure/backup/image/resources/backup.sh similarity index 100% rename from infrastructure/docker-backup/image/resources/backup.sh rename to infrastructure/backup/image/resources/backup.sh diff --git a/infrastructure/docker-backup/image/resources/entrypoint-start-and-wait.sh b/infrastructure/backup/image/resources/entrypoint-start-and-wait.sh similarity index 100% rename from infrastructure/docker-backup/image/resources/entrypoint-start-and-wait.sh rename to infrastructure/backup/image/resources/entrypoint-start-and-wait.sh diff --git a/infrastructure/docker-backup/image/resources/entrypoint.sh b/infrastructure/backup/image/resources/entrypoint.sh similarity index 100% rename from infrastructure/docker-backup/image/resources/entrypoint.sh rename to infrastructure/backup/image/resources/entrypoint.sh diff --git a/infrastructure/docker-backup/image/resources/init.sh b/infrastructure/backup/image/resources/init.sh similarity index 100% rename from infrastructure/docker-backup/image/resources/init.sh rename to infrastructure/backup/image/resources/init.sh diff --git a/infrastructure/docker-backup/image/resources/install.sh b/infrastructure/backup/image/resources/install.sh similarity index 100% rename from infrastructure/docker-backup/image/resources/install.sh rename to infrastructure/backup/image/resources/install.sh diff --git a/infrastructure/docker-backup/image/resources/restic-snapshots.sh b/infrastructure/backup/image/resources/restic-snapshots.sh similarity index 100% rename from infrastructure/docker-backup/image/resources/restic-snapshots.sh rename to infrastructure/backup/image/resources/restic-snapshots.sh diff --git a/infrastructure/docker-backup/image/resources/restore.sh b/infrastructure/backup/image/resources/restore.sh similarity index 100% rename from infrastructure/docker-backup/image/resources/restore.sh rename to infrastructure/backup/image/resources/restore.sh diff --git a/infrastructure/docker-backup/test/Dockerfile b/infrastructure/backup/test/Dockerfile similarity index 100% rename from infrastructure/docker-backup/test/Dockerfile rename to infrastructure/backup/test/Dockerfile diff --git a/infrastructure/docker-backup/test/serverspec.edn b/infrastructure/backup/test/serverspec.edn similarity index 100% rename from infrastructure/docker-backup/test/serverspec.edn rename to infrastructure/backup/test/serverspec.edn diff --git a/infrastructure/docker-federated/build.py b/infrastructure/federated/build.py similarity index 69% rename from infrastructure/docker-federated/build.py rename to infrastructure/federated/build.py index 63f4b27..f4ada60 100644 --- a/infrastructure/docker-federated/build.py +++ b/infrastructure/federated/build.py @@ -1,13 +1,19 @@ from os import environ +from datetime import datetime from pybuilder.core import task, init from ddadevops import * -name = 'c4k-forgejo-federated' -MODULE = 'docker' +name = 'c4k-forgejo' +MODULE = 'federated' PROJECT_ROOT_PATH = '../..' +version = "3.0.4-SNAPSHOT" @init def initialize(project): + image_tag = version + if "dev" in image_tag: + image_tag += datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + input = { "name": name, "module": MODULE, @@ -15,9 +21,11 @@ def initialize(project): "project_root_path": PROJECT_ROOT_PATH, "build_types": ["IMAGE"], "mixin_types": [], + "image_naming": "NAME_AND_MODULE", + "image_tag": f"{image_tag}", } - project.build_depends_on('ddadevops>=4.0.0-dev') + project.build_depends_on("ddadevops>=4.7.0") build = DevopsImageBuild(project, input) build.initialize_build_dir() @@ -33,13 +41,15 @@ def drun(project): build = get_devops_build(project) build.drun() -@task -def publish(project): - build = get_devops_build(project) - build.dockerhub_login() - build.dockerhub_publish() @task def test(project): build = get_devops_build(project) build.test() + + +@task +def publish(project): + build = get_devops_build(project) + build.dockerhub_login() + build.dockerhub_publish() diff --git a/infrastructure/docker-federated/image/Dockerfile b/infrastructure/federated/image/Dockerfile similarity index 100% rename from infrastructure/docker-federated/image/Dockerfile rename to infrastructure/federated/image/Dockerfile diff --git a/infrastructure/docker-federated/test/Dockerfile b/infrastructure/federated/test/Dockerfile similarity index 100% rename from infrastructure/docker-federated/test/Dockerfile rename to infrastructure/federated/test/Dockerfile diff --git a/infrastructure/docker-federated/test/serverspec.edn b/infrastructure/federated/test/serverspec.edn similarity index 100% rename from infrastructure/docker-federated/test/serverspec.edn rename to infrastructure/federated/test/serverspec.edn