diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 07faa88b..e920181d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,10 +16,10 @@ yamllint: stage: lint image: registry.gitlab.com/pipeline-components/yamllint:latest tags: - - 'docker' + - "docker" rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - - if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS' + - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" when: never script: - yamllint . @@ -28,10 +28,10 @@ jsonlint: stage: lint image: registry.gitlab.com/pipeline-components/jsonlint:latest tags: - - 'docker' + - "docker" rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - - if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS' + - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" when: never script: - | @@ -42,35 +42,35 @@ black: stage: lint image: registry.gitlab.com/pipeline-components/black:latest tags: - - 'docker' + - "docker" rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - - if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS' + - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" when: never script: - black --check --verbose -- . pylint: stage: lint - image: python:3.7-slim + image: registry.gitlab.com/pipeline-components/pylint:latest tags: - - 'docker' + - "docker" rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - - if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS' + - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" when: never - before_script: - - mkdir -p public/badges public/lint - - echo undefined > public/badges/$CI_JOB_NAME.score - - pip install pylint-gitlab + # before_script: + # - mkdir -p public/badges public/lint + # - echo undefined > public/badges/$CI_JOB_NAME.score script: - - pylint --exit-zero --output-format=text $(find -type f -name "*.py" ! -path "**/.venv/**" ! -path "**/app/migrations/**") | tee /tmp/pylint.txt - - sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' /tmp/pylint.txt > public/badges/$CI_JOB_NAME.score + # - pylint --exit-zero --output-format=text $(find -type f -name "*.py" ! -path "**/.venv/**" ! -path "**/app/migrations/**") | tee /tmp/pylint.txt + # - sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' /tmp/pylint.txt > public/badges/$CI_JOB_NAME.score - pylint --exit-zero --output-format=pylint_gitlab.GitlabCodeClimateReporter $(find -type f -name "*.py" ! -path "**/.venv/**" ! -path "**/app/migrations/**") > codeclimate.json - after_script: - - anybadge --overwrite --label $CI_JOB_NAME --value=$(cat public/badges/$CI_JOB_NAME.score) --file=public/badges/$CI_JOB_NAME.svg 4=red 6=orange 8=yellow 10=green - - | - echo "Your score is: $(cat public/badges/$CI_JOB_NAME.score)" + # after_script: + # - anybadge --overwrite --label $CI_JOB_NAME --value=$(cat public/badges/$CI_JOB_NAME.score) --file=public/badges/$CI_JOB_NAME.svg 4=red 6=orange 8=yellow 10=green + # - | + # echo "Your score is: $(cat public/badges/$CI_JOB_NAME.score)" + # Removed lint badge generation until public release artifacts: paths: - public @@ -84,12 +84,18 @@ docker-build-dev: - name: docker:dind stage: dev-deployment tags: - - 'docker_priv' + - "docker_priv" rules: - if: $CI_COMMIT_BRANCH == 'dev' environment: name: development before_script: + - | + apk --no-cache add jq + MAJOR=$(cat app/config/version.json | jq '.major' ) + MINOR=$(cat app/config/version.json | jq '.minor' ) + SUB=$(cat app/config/version.json | jq '.sub' ) + META=$(cat app/config/version.json | jq '.meta' ) - | apk --no-cache add curl latest_tag=$(curl -s https://api.github.com/repos/docker/buildx/releases/latest | sed -Ene '/^ *"tag_name": *"(v.+)",$/s//\1/p') @@ -105,12 +111,18 @@ docker-build-dev: script: - | tag=":$CI_COMMIT_REF_SLUG" + VERSION="${MAJOR}.${MINOR}.${SUB}-${META}" + - | echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag" + echo "Crafty Version: $VERSION" - docker context create tls-environment - docker buildx create --name zedBuilder --use tls-environment - docker buildx build --cache-from type=registry,ref="$CI_REGISTRY_IMAGE${tag}" --build-arg BUILDKIT_INLINE_CACHE=1 + --build-arg "BUILD_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ")" + --build-arg "BUILD_REF=${CI_COMMIT_SHA}" + --build-arg "CRAFTY_VER=${VERSION}" --tag "$CI_REGISTRY_IMAGE${tag}" --platform linux/arm64/v8,linux/amd64 --push . @@ -127,12 +139,18 @@ docker-build-prod: - name: docker:dind stage: prod-deployment tags: - - 'docker_priv' + - "docker_priv" rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH environment: name: production before_script: + - | + apk --no-cache add jq + MAJOR=$(cat app/config/version.json | jq '.major' ) + MINOR=$(cat app/config/version.json | jq '.minor' ) + SUB=$(cat app/config/version.json | jq '.sub' ) + META=$(cat app/config/version.json | jq '.meta' ) - | apk --no-cache add curl latest_tag=$(curl -s https://api.github.com/repos/docker/buildx/releases/latest | sed -Ene '/^ *"tag_name": *"(v.+)",$/s//\1/p') @@ -148,12 +166,18 @@ docker-build-prod: script: - | tag="" - echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'" + VERSION="${MAJOR}.${MINOR}.${SUB}-${META}" + - | + echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag" + echo "Crafty Version: $VERSION" - docker context create tls-environment - docker buildx create --name zedBuilder --use tls-environment - docker buildx build --cache-from type=registry,ref="$CI_REGISTRY_IMAGE${tag}" --build-arg BUILDKIT_INLINE_CACHE=1 + --build-arg "BUILD_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ")" + --build-arg "BUILD_REF=${CI_COMMIT_SHA}" + --build-arg "CRAFTY_VER=${VERSION}" --tag "$CI_REGISTRY_IMAGE${tag}" --platform linux/arm64/v8,linux/amd64 --push . @@ -205,7 +229,6 @@ win-dev-build: exclude: - app\classes\**\* - win-prod-build: stage: prod-deployment tags: diff --git a/Dockerfile b/Dockerfile index 140d5122..f293c2e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,23 @@ FROM ubuntu:20.04 ENV DEBIAN_FRONTEND="noninteractive" +ARG BUILD_DATE +ARG BUILD_REF +ARG CRAFTY_VER -LABEL maintainer="Dockerfile created by Zedifus " +# Add meta labels +LABEL \ + maintainer="Zedifus " \ + org.opencontainers.image.created=${BUILD_DATE} \ + org.opencontainers.image.revision=${BUILD_REF} \ + org.opencontainers.image.version=${CRAFTY_VER} \ + org.opencontainers.image.title="Crafty Controller" \ + org.opencontainers.image.description="A Game Server Control Panel / Launcher" \ + org.opencontainers.image.url="https://craftycontrol.com/" \ + org.opencontainers.image.documentation="https://wiki.craftycontrol.com/" \ + org.opencontainers.image.source="https://gitlab.com/crafty-controller/crafty-commander" \ + org.opencontainers.image.vendor="Arcadia Technology, LLC." \ + org.opencontainers.image.licenses="" # Security Patch for CVE-2021-44228 ENV LOG4J_FORMAT_MSG_NO_LOOKUPS=true