From f43f265c7f1691c58bcdf8bb4ec0a0bf8fb0be6f Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 8 May 2023 10:19:40 +0930 Subject: [PATCH] ci: added initial ci jobs !3 --- .cz.yaml | 7 +++ .gitlab-ci.yml | 157 ++++++++++++++++++++++++++++++++++++++++--------- .gitmodules | 3 + gitlab-ci | 1 + 4 files changed, 141 insertions(+), 27 deletions(-) create mode 100644 .cz.yaml create mode 100644 .gitmodules create mode 160000 gitlab-ci diff --git a/.cz.yaml b/.cz.yaml new file mode 100644 index 0000000..62b2ada --- /dev/null +++ b/.cz.yaml @@ -0,0 +1,7 @@ +commitizen: + bump_message: "build(version): bump version $current_version \u2192 $new_version" + changelog_incremental: false + name: cz_conventional_commits + tag_format: $major.$minor.$patch$prerelease + update_changelog_on_bump: true + version: 0.0.1 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3afa28c..873f467 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,36 +1,139 @@ stages: - validation + - build + - prepare + - test + - release - sync + - publish + +include: + - project: nofusscomputing/projects/gitlab-ci + ref: 36ce0b0b76e6769c7a2e0d4ea0f3fcd2cc2d6bb1 + file: + - conventional_commits/.gitlab-ci.yml + - gitlab_release/.gitlab-ci.yml + - git_push_mirror/.gitlab-ci.yml + + +Docker Container: + stage: build + image: docker:latest + services: + #- docker:19.03.12-dind + - docker:latest-dind + variables: + IMAGE_NAME: ansible-ee + before_script: + - docker info +# - docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - apk update + - apk add --update --no-cache python3 git && ln -sf python3 /usr/bin/python + - python3 -m ensurepip + - pip3 install -r gitlab-ci/gitlab_release/requirements.txt + - pip3 install gitlab-ci/gitlab_release/python-module/cz_nfc/. + script: | + docker build . \ + --label org.opencontainers.image.created="$(date '+%Y-%m-%d %H:%M:%S%:z')" \ + --label org.opencontainers.image.documentation="$CI_PROJECT_URL" \ + --label org.opencontainers.image.source="$CI_PROJECT_URL" \ + --label org.opencontainers.image.url="$CI_PROJECT_URL/-/releases/$(cz -n cz_nfc version --project)" \ + --label org.opencontainers.image.version="$(cz -n cz_nfc version --project)" \ + --label org.opencontainers.image.revision="$CI_COMMIT_SHA" \ + --no-cache \ + --tag $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA; + + docker image inspect $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA; + + docker push $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA; + + #allow_failure: true + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + when: never + - if: $CI_COMMIT_TAG + when: on_success + # - if: '$CI_COMMIT_BRANCH == "development" && $CI_COMMIT_TITLE =~ /Merge branch.*/' + # when: on_success + - if: '$CI_COMMIT_BRANCH != "master"' + allow_failure: true + when: manual + - when: never + + + +Docker Hub: + stage: publish + image: docker:latest + services: + #- docker:19.03.12-dind + - docker:latest-dind + variables: + IMAGE_NAME: ansible-ee + before_script: + - export + - docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD + - docker pull $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA + - docker logout $CI_REGISTRY + script: +# - Release_TAG=$(cat $CI_PROJECT_DIR/dist/version) + - docker login docker.io -u $NFC_DOCKERHUB_USERNAME -p $NFC_DOCKERHUB_TOKEN +# - if [ "m$(echo $CI_BUILD_REF_NAME | grep rc)" == "m$CI_BUILD_REF_NAME" ]; then Branch_TAG=dev; else Branch_TAG=stable; fi + - echo Branch tag is $Branch_TAG + - docker image ls + - | + if [ "0$CI_COMMIT_BRANCH" == "0development" ]; then + + DH_LATEST_TAG=dev + + elif [ "0$CI_COMMIT_TAG" != "0" ] ; then + + if [ "0$CI_COMMIT_TAG" == *"rc"* ]; then + + DH_LATEST_TAG=dev + + else + + DH_LATEST_TAG=latest + + fi + + docker image tag $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA nofusscomputing/$IMAGE_NAME:$CI_COMMIT_TAG; + + docker image ls; + + docker push nofusscomputing/$IMAGE_NAME:$CI_COMMIT_TAG; + + fi + + if [ "0$DH_LATEST_TAG" != "0" ]; then + + docker image tag $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA nofusscomputing/$IMAGE_NAME:$DH_LATEST_TAG; + + docker image ls; + + docker push nofusscomputing/$IMAGE_NAME:$DH_LATEST_TAG; + + fi + needs: [ "Docker Container" ] + environment: + name: DockerHub + url: https://hub.docker.com/r/nofusscomputing/docker-mail + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + when: never + - if: $CI_COMMIT_TAG + when: on_success + # - if: '$CI_COMMIT_BRANCH == "development" && $CI_COMMIT_TITLE =~ /Merge branch.*/' + # when: on_success + - if: '$CI_COMMIT_BRANCH != "master"' + allow_failure: true + when: manual + - when: never -dummy: - image: alpine:latest - stage: validation - script: - - echo dummy job - rules: - - if: "$CI_COMMIT_BRANCH" - when: always - - when: never -.git_push_mirror: - image: alpine:latest - stage: sync - before_script: - - apk update - - apk add git - script: - - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/$CI_PROJECT_PATH --mirror $CI_PROJECT_NAME - - cd $CI_PROJECT_NAME - - git remote add destination $GIT_SYNC_URL - - echo "https://gitlab.com/ $CI_PROJECT_PATH / $CI_PROJECT_NAME .git" - - git push destination --mirror - artifacts: - expire_in: 1 day - rules: - - if: '$CI_COMMIT_BRANCH == "master"' - - if: '$CI_COMMIT_BRANCH == "development"' - when: always Github (Push --mirror): diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..abc28e7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "gitlab-ci"] + path = gitlab-ci + url = https://gitlab.com/nofusscomputing/projects/gitlab-ci.git diff --git a/gitlab-ci b/gitlab-ci new file mode 160000 index 0000000..36ce0b0 --- /dev/null +++ b/gitlab-ci @@ -0,0 +1 @@ +Subproject commit 36ce0b0b76e6769c7a2e0d4ea0f3fcd2cc2d6bb1