Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pre and post-rollout tasks bash scripts with build-deploy-tool #3146

Merged
merged 8 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions docs/using-lagoon-the-basics/lagoon-yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ Common uses for post-rollout tasks include running `drush updb`, `drush cim`, or
* The service which to run the task in. If following our Drupal example, this will be the CLI container, as it has all your site code, files, and a connection to the database. Typically you do not need to change this.
* `shell`
* Which shell should be used to run the task in. By default `sh` is used, but if the container also has other shells \(like `bash`, you can define it here\). This is useful if you want to run some small if/else bash scripts within the post-rollouts. \(see the example above how to write a script with multiple lines\).
* `when`
* The "when" clause allows for the conditional running of tasks. It expects an expression that will evaluate to a true/false value which determines whether the task should be run.

Note: If you would like to temporarily disable pre/post-rollout tasks during a deployment, you can set either of the following environment variables in the API at the project or environment level \(see how on [Environment Variables](../using-lagoon-advanced/environment-variables.md)\).

* `LAGOON_PREROLLOUT_DISABLED=true`
* `LAGOON_POSTROLLOUT_DISABLED=true`


#### Example post-rollout tasks

Here are some useful examples of post-rollout tasks that you may want to use or adapt for your projects.
Expand All @@ -75,12 +78,9 @@ Different tasks based on branch name:
- run:
name: Different tasks based on Branch Name
command: |
if [[ "$LAGOON_GIT_BRANCH" != "production" ]]; then
### Runs if current branch is not 'production'
else
### Runs if current branch is 'production'
fi
service: cli
when: LAGOON_GIT_BRANCH != "production"
```

Run shell script:
Expand All @@ -98,14 +98,13 @@ Drupal & Drush 9: Sync database & files from master environment:
- run:
name: Sync DB and Files from master if we are not on master
command: |
if [[ "$LAGOON_GIT_BRANCH" != "master" ]]; then
# Only if we don't have a database yet
if tables=$(drush sqlq 'show tables;') && [ -z "$tables" ]; then
drush sql-sync @lagoon.master @self
drush rsync @lagoon.master:%files @self:%files -- --omit-dir-times --no-perms --no-group --no-owner --chmod=ugo=rwX
fi
# Only if we don't have a database yet
if tables=$(drush sqlq 'show tables;') && [ -z "$tables" ]; then
drush sql-sync @lagoon.master @self
drush rsync @lagoon.master:%files @self:%files -- --omit-dir-times --no-perms --no-group --no-owner --chmod=ugo=rwX
fi
service: cli
when: LAGOON_ENVIRONMENT_TYPE != "production"
```

## Backup Retention
Expand Down
2 changes: 1 addition & 1 deletion images/kubectl-build-deploy-dind/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ENV DBAAS_OPERATOR_HTTP=dbaas.lagoon.svc:5000
RUN curl -sSL https://github.com/uselagoon/lagoon-linter/releases/download/v0.7.0/lagoon-linter_0.7.0_linux_amd64.tar.gz \
| tar -xz -C /usr/local/bin lagoon-linter

RUN curl -sSL https://github.com/uselagoon/build-deploy-tool/releases/download/v0.7.7/build-deploy-tool_0.7.7_linux_amd64.tar.gz \
RUN curl -sSL https://github.com/uselagoon/build-deploy-tool/releases/download/v0.8.5/build-deploy-tool_0.8.5_linux_amd64.tar.gz \
| tar -xz -C /usr/local/bin build-deploy-tool

RUN curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin > /dev/null 2>&1
Expand Down
44 changes: 3 additions & 41 deletions images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -661,26 +661,7 @@ set -x
##############################################

if [ "${LAGOON_PREROLLOUT_DISABLED}" != "true" ]; then
bomoko marked this conversation as resolved.
Show resolved Hide resolved
COUNTER=0
while [ -n "$(cat .lagoon.yml | shyaml keys tasks.pre-rollout.$COUNTER 2> /dev/null)" ]
do
TASK_TYPE=$(cat .lagoon.yml | shyaml keys tasks.pre-rollout.$COUNTER)
echo $TASK_TYPE
case "$TASK_TYPE" in
run)
COMMAND=$(cat .lagoon.yml | shyaml get-value tasks.pre-rollout.$COUNTER.$TASK_TYPE.command)
SERVICE_NAME=$(cat .lagoon.yml | shyaml get-value tasks.pre-rollout.$COUNTER.$TASK_TYPE.service)
CONTAINER=$(cat .lagoon.yml | shyaml get-value tasks.pre-rollout.$COUNTER.$TASK_TYPE.container false)
SHELL=$(cat .lagoon.yml | shyaml get-value tasks.pre-rollout.$COUNTER.$TASK_TYPE.shell sh)
. /kubectl-build-deploy/scripts/exec-pre-tasks-run.sh
;;
*)
echo "Task Type ${TASK_TYPE} not implemented"; exit 1;

esac

let COUNTER=COUNTER+1
done
build-deploy-tool tasks pre-rollout
else
echo "pre-rollout tasks are currently disabled LAGOON_PREROLLOUT_DISABLED is set to true"
fi
Expand Down Expand Up @@ -1001,7 +982,7 @@ set -x
# so just add https...
ROUTE=$(build-deploy-tool identify primary-ingress)
if [ ! -z "${ROUTE}" ]; then
ROUTE=https://${ROUTE}
ROUTE=${ROUTE}
fi

# Load all routes with correct schema and comma separated
Expand Down Expand Up @@ -1399,26 +1380,7 @@ set -x

# if we have LAGOON_POSTROLLOUT_DISABLED set, don't try to run any pre-rollout tasks
if [ "${LAGOON_POSTROLLOUT_DISABLED}" != "true" ]; then
bomoko marked this conversation as resolved.
Show resolved Hide resolved
COUNTER=0
while [ -n "$(cat .lagoon.yml | shyaml keys tasks.post-rollout.$COUNTER 2> /dev/null)" ]
do
TASK_TYPE=$(cat .lagoon.yml | shyaml keys tasks.post-rollout.$COUNTER)
echo $TASK_TYPE
case "$TASK_TYPE" in
run)
COMMAND=$(cat .lagoon.yml | shyaml get-value tasks.post-rollout.$COUNTER.$TASK_TYPE.command)
SERVICE_NAME=$(cat .lagoon.yml | shyaml get-value tasks.post-rollout.$COUNTER.$TASK_TYPE.service)
CONTAINER=$(cat .lagoon.yml | shyaml get-value tasks.post-rollout.$COUNTER.$TASK_TYPE.container false)
SHELL=$(cat .lagoon.yml | shyaml get-value tasks.post-rollout.$COUNTER.$TASK_TYPE.shell sh)
. /kubectl-build-deploy/scripts/exec-tasks-run.sh
;;
*)
echo "Task Type ${TASK_TYPE} not implemented"; exit 1;

esac

let COUNTER=COUNTER+1
done
build-deploy-tool tasks post-rollout
else
echo "post-rollout tasks are currently disabled LAGOON_POSTROLLOUT_DISABLED is set to true"
fi
Expand Down
29 changes: 0 additions & 29 deletions images/kubectl-build-deploy-dind/scripts/exec-pre-tasks-run.sh

This file was deleted.

28 changes: 0 additions & 28 deletions images/kubectl-build-deploy-dind/scripts/exec-tasks-run.sh

This file was deleted.