From b9f7a8fd119c44a8d83d8f53d4d2997104ed4d13 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Thu, 21 Mar 2024 00:07:20 +0100 Subject: [PATCH 1/6] v1.2.0: ci: ci and makefile Signed-off-by: GnomeZworc --- .gitlab-ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 28 ++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 Makefile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..6f51382 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,46 @@ +default: + image: debian:11 + +stages: + - build + - publish + - release + +build: + stage: build + image: golang:1.21-alpine + before_script: + - apk update && apk add --no-cache make git + script: + - make build_password + artifacts: + paths: + - ./bin/* + +publish_main: + stage: publish + image: golang:1.21-alpine + variables: + VER: latest + before_script: + - apk update && apk add --no-cache make git curl + script: + - make publish_password + needs: + - build + only: + - main + +release_tag: + stage: publish + image: golang:1.21-alpine + variables: + VER: ${CI_COMMIT_TAG} + before_script: + - apk update && apk add --no-cache make git curl + script: + - make publish_password + needs: + - build + only: + - tags \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8a6bf90 --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +ARCH := amd64 arm64 +OS := linux windows darwin +NAME := password +VERSION := $(shell git describe) +BUILD := $(shell git rev-parse HEAD) + +LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD}" + +.PHONY: all build + +all: build + +build_password: + $(foreach GOOS, ${OS},\ + $(foreach GOARCH, ${ARCH}, \ + $(shell CGO_ENABLED=0 go build -v -o bin/${NAME} ./golang/cmd/passwordhash;cd bin/;[ "${GOOS}" = "windows" ] && mv ${NAME} ${NAME}.exe;tar czf ${NAME}_${GOOS}_${GOARCH}.tar.gz *;rm -f ${NAME} ${NAME}.exe) \ + )) + +publish_password: + $(foreach GOOS, ${OS},\ + $(foreach GOARCH, ${ARCH}, \ + $(curl --silent --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/${NAME}_${GOOS}_${GOARCH}.tar.gz "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${NAME}/${VER}/${NAME}_${GOOS}_${GOARCH}.tar.gz") \ + )) + +clean: + rm -rf bin + +re: clean all \ No newline at end of file From b3c850eb7b812e7d7302340421d5fc9a0a7f2a7f Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Thu, 21 Mar 2024 13:59:37 +0100 Subject: [PATCH 2/6] v1.2.0: release: first script for release on gitlab Signed-off-by: GnomeZworc --- .gitlab-ci.yml | 14 +++++++- docs/release/v0.3.0_nicolas.md | 7 ++++ scripts/gitlab_release.sh | 61 ++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 docs/release/v0.3.0_nicolas.md create mode 100644 scripts/gitlab_release.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6f51382..172757e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -43,4 +43,16 @@ release_tag: needs: - build only: - - tags \ No newline at end of file + - tags + +release_job: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + rules: + - if: $CI_COMMIT_TAG + before_script: + - apk update && apk add --no-cache bash curl + script: + - bash ./scripts/gitlab_release.sh -r ./docs/release/$CI_COMMIT_TAG* -a ./bin/ + needs: + - build \ No newline at end of file diff --git a/docs/release/v0.3.0_nicolas.md b/docs/release/v0.3.0_nicolas.md new file mode 100644 index 0000000..1884b8d --- /dev/null +++ b/docs/release/v0.3.0_nicolas.md @@ -0,0 +1,7 @@ +# Nicolas v0.3.0 + +## Release feature + +- toto +- tata +- arno diff --git a/scripts/gitlab_release.sh b/scripts/gitlab_release.sh new file mode 100644 index 0000000..ecc5f88 --- /dev/null +++ b/scripts/gitlab_release.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +exec_with_dry_run () { + if [[ ${1} -eq ${FLAGS_TRUE} ]]; then + echo "# ${2}" + else + eval "${2}" 2> /tmp/error || \ + { + echo -e "failed with following error"; + output=$(cat /tmp/error | sed -e "s/^/ error -> /g"); + echo -e "${output}"; + return 1; + } + fi + return 0 +} + + +main () { + [[ -f ./libs/shflags ]] && . ./libs/shflags || eval "$(curl --silent https://gitlab.g3e.fr/h6n/tools/-/raw/main/libs/shflags)" + [[ -f ./.config/gitlab_release ]] && . ./.config/gitlab_release + + DEFINE_string 'artifact_path' '' 'Path of artifact list' 'a' + DEFINE_boolean 'dryrun' false 'Enable dry-run mode' 'd' + DEFINE_string 'release_path' '' 'Release documentation path' 'r' + DEFINE_string 'skip_line' '2' 'Number of line to skip in release file' 's' + + FLAGS "$@" || exit $? + eval set -- "${FLAGS_ARGV}" + + [[ ${FLAGS_release_path} == "" ]] && \ + { + echo "error release_path as to be filled" + return 1 + } + + NAME=$(cat ${FLAGS_release_path} | head -n 1 | cut -d\ -f 2) + VERSION=$(cat ${FLAGS_release_path} | head -n 1 | cut -d\ -f 3) + BODY=$(tail +${FLAGS_skip_line} ${FLAGS_release_path}) + + ASSET=$(ls ${FLAGS_artifact_path} | while read asset + do + asset_name=$(echo ${asset} | cut -d_ -f1) + echo -n " --assets-link '{\"name\":\"${asset}\",\"url\":\"${CI_API_V4_URL}/projects/${VERSION}/packages/generic/${asset_name}/${VERSION}/${asset}\",\"link_type\":\"package\"}'" + done + for docker in ${CONTAINER_LIST[@]} + do + echo -n " --assets-link '{\"name\":\"registry.g3e.fr/h6n/${docker}:${VERSION}\",\"url\":\"https://registry.g3e.fr/h6n/${docker}\",\"link_type\":\"image\"}'" + done) + + + echo "# ${NAME} ${VERSION}" + + exec_with_dry_run ${FLAGS_dryrun} "release-cli create --name '${NAME}' --description '${BODY}' \ + --tag-name '${VERSION}' --ref '${VERSION}' \ + --milestone '${VERSION}' \ + ${ASSET}" +} + +[[ "${BASH_SOURCE[0]}" == "${0}" ]] && (main "$@" || exit 1) +[[ "${BASH_SOURCE[0]}" == "" ]] && (main "$@" || exit 1) \ No newline at end of file From 042215b8dd62621a084cc56784f1fb0e5bc0ef28 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Thu, 21 Mar 2024 18:07:01 +0100 Subject: [PATCH 3/6] v1.2.0: ci: fix release Signed-off-by: GnomeZworc --- scripts/gitlab_release.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/gitlab_release.sh b/scripts/gitlab_release.sh index ecc5f88..6a85d01 100644 --- a/scripts/gitlab_release.sh +++ b/scripts/gitlab_release.sh @@ -51,11 +51,18 @@ main () { echo "# ${NAME} ${VERSION}" - exec_with_dry_run ${FLAGS_dryrun} "release-cli create --name '${NAME}' --description '${BODY}' \ + exec_with_dry_run ${FLAGS_dryrun} "/usr/local/bin/release-cli create --name '${NAME}' --description '${BODY}' \ --tag-name '${VERSION}' --ref '${VERSION}' \ --milestone '${VERSION}' \ ${ASSET}" + return 0 } -[[ "${BASH_SOURCE[0]}" == "${0}" ]] && (main "$@" || exit 1) -[[ "${BASH_SOURCE[0]}" == "" ]] && (main "$@" || exit 1) \ No newline at end of file +[[ "${BASH_SOURCE[0]}" == "${0}" ]] && \ + { + main "$@" && exit 0 || exit 1 + } +[[ "${BASH_SOURCE[0]}" == "" ]] && \ + { + main "$@" && exit 0 || exit 1 + } \ No newline at end of file From e5c0ed234818d82a6076c1d53af6dc4cff4a8653 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Sun, 24 Mar 2024 12:48:24 +0100 Subject: [PATCH 4/6] doc: add small limited doc for password hasher Signed-off-by: GnomeZworc --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9cbccad..ada7c06 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,8 @@ v1.0.0: Damian To use the release script it's simple `curl https://gitlab.g3e.fr/h6n/tools/-/raw/main/scripts/release.sh | bash -s - [param list]` -In dev mode you can do `cat ./scripts/release.sh | bash -s - [param list]` \ No newline at end of file +In dev mode you can do `cat ./scripts/release.sh | bash -s - [param list]` + +## Password hasher + +To use the password hasher you only need to download it, give him exec right and launch it, all is done locally and nothing is exported. \ No newline at end of file From faa767ee08b921ab35931f9504a764c4d77c5624 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Tue, 2 Apr 2024 23:53:24 +0200 Subject: [PATCH 5/6] v1.2.0: script: add a gitlab-ci script Signed-off-by: GnomeZworc --- config-ci/.gitlab-ci.yml.j2 | 58 +++++++++++++++++++++++++++++++++++ config/params.json | 2 ++ scripts/update_ci.sh | 60 +++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 config-ci/.gitlab-ci.yml.j2 create mode 100644 config/params.json create mode 100755 scripts/update_ci.sh diff --git a/config-ci/.gitlab-ci.yml.j2 b/config-ci/.gitlab-ci.yml.j2 new file mode 100644 index 0000000..172757e --- /dev/null +++ b/config-ci/.gitlab-ci.yml.j2 @@ -0,0 +1,58 @@ +default: + image: debian:11 + +stages: + - build + - publish + - release + +build: + stage: build + image: golang:1.21-alpine + before_script: + - apk update && apk add --no-cache make git + script: + - make build_password + artifacts: + paths: + - ./bin/* + +publish_main: + stage: publish + image: golang:1.21-alpine + variables: + VER: latest + before_script: + - apk update && apk add --no-cache make git curl + script: + - make publish_password + needs: + - build + only: + - main + +release_tag: + stage: publish + image: golang:1.21-alpine + variables: + VER: ${CI_COMMIT_TAG} + before_script: + - apk update && apk add --no-cache make git curl + script: + - make publish_password + needs: + - build + only: + - tags + +release_job: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + rules: + - if: $CI_COMMIT_TAG + before_script: + - apk update && apk add --no-cache bash curl + script: + - bash ./scripts/gitlab_release.sh -r ./docs/release/$CI_COMMIT_TAG* -a ./bin/ + needs: + - build \ No newline at end of file diff --git a/config/params.json b/config/params.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/config/params.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/scripts/update_ci.sh b/scripts/update_ci.sh new file mode 100755 index 0000000..4cec188 --- /dev/null +++ b/scripts/update_ci.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +#list="build deploy latest release test" + +#for elem in ${list} +#do +# echo "Build ${elem}" +# j2 -f json \ +# .gitlab/templates/${elem}.yml.j2 \ +# .gitlab/templates/.container_list.json \ +# -o .gitlab/ci/${elem}.yml +#done + +exec_with_dry_run () { + if [[ ${1} -eq ${FLAGS_TRUE} ]]; then + echo "# ${2}" + else + eval "${2}" 2> /tmp/error || \ + { + echo -e "failed with following error"; + output=$(cat /tmp/error | sed -e "s/^/ error -> /g"); + echo -e "${output}"; + return 1; + } + fi + return 0 +} + +main () { + [[ -f ./libs/shflags ]] && . ./libs/shflags || eval "$(curl --silent https://gitlab.g3e.fr/h6n/tools/-/raw/main/libs/shflags)" + + DEFINE_boolean 'dryrun' false 'Enable dry-run mode' 'd' + DEFINE_string 'output_path' '' 'Release documentation path' 'o' + DEFINE_string 'template_path' '' 'Path of artifact list' 't' + DEFINE_string 'params_path' '' 'Path of artifact list' 'p' + + FLAGS "$@" || exit $? + eval set -- "${FLAGS_ARGV}" + + exec_with_dry_run ${FLAGS_dryrun} "pip install j2cli" > /dev/null + + ls -a ${FLAGS_template_path} | while read TEMPLATE + do + file=$(echo ${TEMPLATE} | grep -Ev '^[\.]*$') + [[ ${file} != "" ]] && \ + { + basename=$(echo ${file%.*}) + exec_with_dry_run ${FLAGS_dryrun} "j2 -f json ${FLAGS_template_path}/${file} ${FLAGS_params_path} -o ${FLAGS_output_path}/${basename}" + } + done +} + +[[ "${BASH_SOURCE[0]}" == "${0}" ]] && \ + { + main "$@" && exit 0 || exit 1 + } +[[ "${BASH_SOURCE[0]}" == "" ]] && \ + { + main "$@" && exit 0 || exit 1 + } \ No newline at end of file From e8da1c9ab6d9323e5941ca69178c5a414acf9c0a Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Tue, 2 Apr 2024 23:58:01 +0200 Subject: [PATCH 6/6] release-v1.2.0 Signed-off-by: GnomeZworc --- README.md | 2 +- docs/release/v1.2.0_valentin.md | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 docs/release/v1.2.0_valentin.md diff --git a/README.md b/README.md index ada7c06..5699b12 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Some tools use and dev for h6n, many are in shell/bash could be use in other pro ## Version -v1.0.0: Damian +v1.2.0: Valentin ## release script diff --git a/docs/release/v1.2.0_valentin.md b/docs/release/v1.2.0_valentin.md new file mode 100644 index 0000000..023a2dc --- /dev/null +++ b/docs/release/v1.2.0_valentin.md @@ -0,0 +1,8 @@ +# Valentin v1.2.0 + +## Release feature + +- add release script to auto generate release in gitlab +- add script to generate file from j2 and json +- define a naming policy +- add a hash password code