diff --git a/Dockerfiles/git/Dockerfile b/Dockerfiles/git/Dockerfile index 39bb34b75e92c70de6effa7f4aaaf18f6cb4ac24..10b5a32137da81bfbb68c4ec40abec3fd7ae72a5 100644 --- a/Dockerfiles/git/Dockerfile +++ b/Dockerfiles/git/Dockerfile @@ -8,5 +8,8 @@ RUN apk add git-lfs RUN git lfs install && \ git config --global init.defaultBranch main +COPY ./update_data.sh /tmp/update_data.sh +RUN chmod +x /tmp/update_data.sh + ENTRYPOINT [ "/bin/sh" ] diff --git a/Dockerfiles/git/local_build.sh b/Dockerfiles/git/local_build.sh new file mode 100644 index 0000000000000000000000000000000000000000..e2ca7fc13798dce355093261e4e6d9ef402a8397 --- /dev/null +++ b/Dockerfiles/git/local_build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker build -t git-lfs . --build-arg NAMESPACE_ENV=d01 \ No newline at end of file diff --git a/Dockerfiles/git/update_data.sh b/Dockerfiles/git/update_data.sh index 0cd1498f6c59f22797e4c3e3a141ddd16015e0ee..1c46df0de0255959300b8d7cfa2b4f4cfe6fd087 100644 --- a/Dockerfiles/git/update_data.sh +++ b/Dockerfiles/git/update_data.sh @@ -1,19 +1,38 @@ -#/bin/sh +#!/bin/sh -echo "-------------------------------------------" -echo "GIT_USERNAME=$GIT_USERNAME" -echo "GIT_PASSWORD=$GIT_PASSWORD" -echo "-------------------------------------------" - -mkdir -p /arb-data/source-files/data-recalcul-calque -cd /arb-data/source-files/data-recalcul-calque +# Formatting log line +comment () { + echo -e "\e[39m\t-> $1\e[39m" +} -# Init command does not do a 'git clone' beacause this is only working at the first init time. -# It does a 'git init + git remote add + git fetch + git checkout' instead. -# This works in every case. -[[ ! -d ".git" ]] && { - git init - git remote add origin https://${GIT_USERNAME}:${GIT_PASSWORD}@forge.grandlyon.com/erasme/sources-recalcul-calque.git +# Check the last command return code (must be insterted just after the commend ) +check () { + if [ $? -eq 0 ]; then + comment "\e[32mOk.\e[39m" + else + comment "\e[31mERROR !...\e[39m" + exit 1 + fi; } -git checkout . -git pull origin main + +###################################################################### +# MAIN +###################################################################### +# Cloning or de pulling data to calculate the calq +if [ -d /arb-data/source-files/data-recalcul-calque/.git ]; then + comment "Entering in data directory..." + cd /arb-data/source-files/data-recalcul-calque + check + comment "Pulling last version of data repo..." + git pull origin main + check +else + comment "This is the first time we run this script, we have to clone data repo..." + mkdir -p /arb-data/source-files/data-recalcul-calque + cd /arb-data/source-files + comment "Cloning data..." + git lfs clone https://$GIT_USERNAME:$GIT_PASSWORD@forge.grandlyon.com/erasme/sources-recalcul-calque.git ./data-recalcul-calque/; + check +fi +echo "Data ready !" +exit 0 diff --git a/deployment/jobs/stage-calqul.yml b/deployment/jobs/stage-calqul.yml index 21093193c8cf38eace329603a6a6e2c714f614e5..0ff64713e87a6a3c59be0a5a5fe8d0848c78d937 100644 --- a/deployment/jobs/stage-calqul.yml +++ b/deployment/jobs/stage-calqul.yml @@ -77,10 +77,6 @@ spec: - name: calqul-refresh-repository-${NAMESPACE_ENV} image: registry.forge.grandlyon.com/erasme/script-recalcul-calque/calqul-git-lfs-${NAMESPACE_ENV} imagePullPolicy: Always - command: - - /bin/sh - - -c - - 'env | sort; echo "GIT_USERNAME=${GIT_USERNAME}"; echo "GIT_PASSWORD=${GIT_PASSWORD}";' env: - name: GIT_USERNAME valueFrom: @@ -96,8 +92,10 @@ spec: value: "http://proxyhttppro.grandlyon.fr:8080" - name: HTTPS_PROXY value: "http://proxyhttppro.grandlyon.fr:8080" + command: + - /bin/sh + - -c + - '/tmp/update_data.sh' volumeMounts: - name: arb-data - mountPath: "/arb-data/source-files" - - # - env | sort; if [ -d /arb-data/source-files/data-recalcul-calque/.git ]; then cd /arb-data/source-files/data-recalcul-calque; git pull origin main; else mkdir -p /arb-data/source-files/data-recalcul-calque; cd /arb-data/source-files; echo "GIT_USERNAME=$GIT_USERNAME"; echo "GIT_PASSWORD=$GIT_PASSWORD"; git lfs clone https://$GIT_USERNAME:$GIT_PASSWORD@forge.grandlyon.com/erasme/sources-recalcul-calque.git ./data-recalcul-calque/; fi; echo "Data ready !"; sleep 300; + mountPath: "/arb-data/source-files" \ No newline at end of file