From 1404da082c7c4396688c519e84908c1b21b4c5e4 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Thu, 24 Mar 2022 19:28:37 +0000 Subject: [PATCH 1/7] Remove lint badge generation until public release --- .gitlab-ci.yml | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 07faa88b..d4fec225 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,10 +42,10 @@ 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 -- . @@ -54,23 +54,24 @@ pylint: stage: lint image: python:3.7-slim 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 + # - mkdir -p public/badges public/lint + # - echo undefined > public/badges/$CI_JOB_NAME.score - pip install pylint-gitlab 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,7 +85,7 @@ docker-build-dev: - name: docker:dind stage: dev-deployment tags: - - 'docker_priv' + - "docker_priv" rules: - if: $CI_COMMIT_BRANCH == 'dev' environment: @@ -127,7 +128,7 @@ docker-build-prod: - name: docker:dind stage: prod-deployment tags: - - 'docker_priv' + - "docker_priv" rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH environment: @@ -205,7 +206,6 @@ win-dev-build: exclude: - app\classes\**\* - win-prod-build: stage: prod-deployment tags: From e259d5c3d7789850d31ed0a17b729fba5c34d94c Mon Sep 17 00:00:00 2001 From: Zedifus Date: Thu, 24 Mar 2022 19:34:11 +0000 Subject: [PATCH 2/7] Replace pylint build step with prebuild MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kudos to Robbert Müller https://gitlab.com/mjrider For implimenting my request to include the gitlab plugin for pylint This means we don't have to waste time installing anything --- .gitlab-ci.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d4fec225..b53a836e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,17 +52,16 @@ black: pylint: stage: lint - image: python:3.7-slim + image: registry.gitlab.com/pipeline-components/pylint:latest tags: - "docker" rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - 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 From a548f49759ca450c7c1ccb1ef28116a2d27adfcf Mon Sep 17 00:00:00 2001 From: Zedifus Date: Thu, 24 Mar 2022 21:45:00 +0000 Subject: [PATCH 3/7] Add OCI Annotation Keys --- .gitlab-ci.yml | 26 +++++++++++++++++++++++++- Dockerfile | 17 ++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b53a836e..e920181d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -90,6 +90,12 @@ docker-build-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 . @@ -133,6 +145,12 @@ docker-build-prod: 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 . 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 From 0f41e1ae2515d52ffd581d05737886f887be67c9 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Thu, 24 Mar 2022 22:07:50 +0000 Subject: [PATCH 4/7] Strip string doublequotes from meta jq output --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e920181d..ffa9ff1b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -95,7 +95,7 @@ docker-build-dev: 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' ) + META=$(cat app/config/version.json | jq -r '.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') @@ -150,7 +150,7 @@ docker-build-prod: 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' ) + META=$(cat app/config/version.json | jq -r '.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') From ca78e79076bbd46e82bd539ddf635c87aab778b7 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Thu, 24 Mar 2022 22:47:04 +0000 Subject: [PATCH 5/7] Move our labeling of the image to the end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is so we don't recache all the layers on a version number change That would be silly😅 --- Dockerfile | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index f293c2e2..c72d93ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,6 @@ FROM ubuntu:20.04 ENV DEBIAN_FRONTEND="noninteractive" -ARG BUILD_DATE -ARG BUILD_REF -ARG CRAFTY_VER - -# 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 @@ -71,3 +54,20 @@ EXPOSE 25500-25600 # Start Crafty Commander through wrapper ENTRYPOINT ["/commander/docker_launcher.sh"] CMD ["-v", "-d", "-i"] + +# Add meta labels +ARG BUILD_DATE +ARG BUILD_REF +ARG CRAFTY_VER +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="" From dfe7b05415329e947048c7171c13cdfae3bbfaf7 Mon Sep 17 00:00:00 2001 From: Iain Powrie Date: Sat, 26 Mar 2022 16:46:54 +0000 Subject: [PATCH 6/7] Badge Update Fix supported versions, link correctly to python home --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c3db87f..6d679404 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Crafty Logo](app/frontend/static/assets/images/logo_long.svg)](https://craftycontrol.com) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) -[![Supported Python Versions](https://shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9-blue)](https://gitlab.com/crafty-controller/crafty-commander) +[![Supported Python Versions](https://shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10%20-blue)](https://www.python.org) [![Version(temp-hardcoded)](https://img.shields.io/badge/release-v4.0.0--alpha3.5-orange)](https://gitlab.com/crafty-controller/crafty-commander) [![Code Quality(temp-hardcoded)](https://img.shields.io/badge/code%20quality-10-brightgreen)](https://gitlab.com/crafty-controller/crafty-commander) [![Build Status](https://gitlab.com/crafty-controller/crafty-commander/badges/master/pipeline.svg)](https://gitlab.com/crafty-controller/crafty-commander/-/commits/master) From 03b6c246e6a2db80373c5a0d241aaa6ae3f8342e Mon Sep 17 00:00:00 2001 From: Iain Powrie Date: Sat, 26 Mar 2022 21:33:19 +0000 Subject: [PATCH 7/7] Add default.env to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 74627ae5..bf21675b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ __pycache__/ .env .venv +default.env env/ venv/ ENV/