Skip to content

Commit

Permalink
fix: preview deploy (#1536)
Browse files Browse the repository at this point in the history
* fix: preview deploy

* fix: preview deploy temporary fix

* fix: file name

* fix: update file permission
  • Loading branch information
kevbarns authored Sep 27, 2024
1 parent 5ee72f0 commit acf29c9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .bin/commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function Help() {
echo " release:app Build & Push Docker image releases"
echo " deploy <env> --user <your_username> Deploy application to <env>"
echo " preview:build Build preview"
echo " preview:build:temp Build preview temp"
echo " preview:cleanup --user <your_username> Remove preview from close pull-requests"
echo " vault:edit Edit vault file"
echo " vault:password Show vault password"
Expand Down Expand Up @@ -59,6 +60,10 @@ function preview:build() {
"${SCRIPT_DIR}/build-images.sh" "$@"
}

function preview:build:temp() {
"${SCRIPT_DIR}/build-images-temp.sh" "$@"
}

function preview:cleanup() {
"${SCRIPT_DIR}/run-playbook.sh" "preview_cleanup.yml" "preview"
}
Expand Down
41 changes: 41 additions & 0 deletions .bin/scripts/build-images-temp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -euo pipefail

export VERSION="${1:?"Veuillez préciser la version"}"
mode=${2:?"Veuillez préciser le mode <push|load>"}
shift 2

get_channel() {
local version="$1"
channel=$(echo "$version" | cut -d '-' -f 2)

if [ "$channel" == "$version" ]; then
channel="latest"
else
channel=$(echo $channel | cut -d '.' -f 1 )
fi

echo $channel
}

if [[ $# == "0" ]]; then
echo "Veuillez spécifier les environnements à build (production, recette, preview, local)"
exit 1;
fi;

set +e
docker buildx create --name mna-lba --driver docker-container --config "$SCRIPT_DIR/buildkitd.toml" 2> /dev/null
set -e

if [[ ! -z "${CI:-}" ]]; then
export DEPS_ID=($(md5sum $ROOT_DIR/yarn.lock))
else
export DEPS_ID=""
fi

export CHANNEL=$(get_channel $VERSION)

# "$@" is the list of environements
docker buildx bake --builder mna-lba --${mode} "$@"
docker builder prune --builder mna-lba --keep-storage 20GB --force
docker buildx stop --builder mna-lba
1 change: 1 addition & 0 deletions .bin/zsh-completion
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _mna-lba_completion() {
"release\:interactive:'Interactivelly Build & Push Docker image releases'"
"deploy:'Deploy application to <env>'"
"build\:image:'Build image'"
"build\:image\:temp:'Build image temp'"
"preview\:build:'Build preview from open pull-requests'"
"preview\:cleanup:'Remove preview from close pull-requests'"
"vault\:edit:'Edit vault file'"
Expand Down
2 changes: 1 addition & 1 deletion .infra/ansible/tasks/preview_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

- name: "[{{ pr_number }}] Build local images 0.0.0-{{ pr_number }}"
shell:
cmd: "flock --verbose --close /tmp/deployment_build.lock .bin/mna-lba preview:build 0.0.0-{{ pr_number }} load preview"
cmd: "flock --verbose --close /tmp/deployment_build.lock .bin/mna-lba preview:build:temp 0.0.0-{{ pr_number }} load preview"
chdir: "/opt/app/projects/{{ pr_number }}/repository"
async: 900 # max 15 minutes
poll: 15 # check every 15s
Expand Down

0 comments on commit acf29c9

Please sign in to comment.