Compare commits

...

10 commits

Author SHA1 Message Date
3fa91f30d1 Merge branch 'release-v1.2.0' into 'main'
release-v1.2.0

See merge request h6n/tools!5
2024-04-02 22:00:35 +00:00
e8da1c9ab6
release-v1.2.0
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-02 23:58:01 +02:00
83144074c0 Merge branch '6-issue' into 'main'
Resolve "add script to generate ci from jinja2"

Closes #6

See merge request h6n/tools!4
2024-04-02 21:54:43 +00:00
faa767ee08
v1.2.0: script: add a gitlab-ci script
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-02 23:53:24 +02:00
e5c0ed2348
doc: add small limited doc for password hasher
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-24 12:48:24 +01:00
c51c50d261 Merge branch '7-issue' into 'main'
add release script gitlab-ci

Closes #7

See merge request h6n/tools!3
2024-03-21 17:35:42 +00:00
042215b8dd
v1.2.0: ci: fix release
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-21 18:26:25 +01:00
b3c850eb7b
v1.2.0: release: first script for release on gitlab
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-21 15:56:14 +01:00
c97517ba6c Merge branch '4-issue' into 'main'
Add genereate password

Closes #4

See merge request h6n/tools!2
2024-03-20 23:53:33 +00:00
b9f7a8fd11
v1.2.0: ci: ci and makefile
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-21 00:52:27 +01:00
9 changed files with 295 additions and 2 deletions

58
.gitlab-ci.yml Normal file
View file

@ -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

28
Makefile Normal file
View file

@ -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

View file

@ -4,10 +4,14 @@ 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
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]`
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.

View file

@ -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

2
config/params.json Normal file
View file

@ -0,0 +1,2 @@
{
}

View file

@ -0,0 +1,7 @@
# Nicolas v0.3.0
## Release feature
- toto
- tata
- arno

View file

@ -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

68
scripts/gitlab_release.sh Normal file
View file

@ -0,0 +1,68 @@
#!/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} "/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 0 || exit 1
}
[[ "${BASH_SOURCE[0]}" == "" ]] && \
{
main "$@" && exit 0 || exit 1
}

60
scripts/update_ci.sh Executable file
View file

@ -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
}