uselagoon / lagoon

Lagoon, the developer-focused application delivery platform
https://docs.lagoon.sh/
Apache License 2.0
560 stars 149 forks source link

Promote deployment does not consider branchRef of promoted environment/deployment for branch checkout #3681

Open sjerdo opened 6 months ago

sjerdo commented 6 months ago

Describe the bug

Promote deployments do not promote the exact deployment of one environment to another.

When the branch is changed or does not yet contain all changes which are included in the deployed branchRef, this could affect in incorrect services being deployed (if docker-compose.yml was changed)

To Reproduce

Deploy a branchRef to environment develop using a tag (eg 1.0.0)

lagoon deploy branch --branch develop --branchRef=1.0.0

Then promote the latest deployment of this environment to another environment, eg. main.

lagoon deploy promote --project PROJECT -s develop -d main

In the logs for the develop deployment, we see these git checkout commands for step 'Checkout Repository':

+ REMOTE=git@gitlab.com:PATH/TO/PROJECT.git
+ REF=1.0.0
+ git init .
Initialized empty Git repository in /kubectl-build-deploy/git/.git/
+ git config remote.origin.url git@gitlab.com:PATH/TO/PROJECT.git
+ git fetch --depth=10 --tags --progress git@gitlab.com:PATH/TO/PROJECT.git '+refs/heads/*:refs/remotes/origin/*'
+ git checkout --force 1.0.0
Note: switching to '27.0.1'.
...
HEAD is now at 2031482a Merge branch 'feature/branch' into 'develop'
+ git submodule update --init --recursive --jobs=6
+ [[ -n '' ]]
+ '[' '!' -f .lagoon.yml ']'
++ cat .lagoon.yml
++ shyaml get-value environment_variables.git_sha false
+ INJECT_GIT_SHA=false
+ '[' false == true ']'
+ LAGOON_GIT_SHA=0000000000000000000000000000000000000000

In the logs for the the promote deployment to main, we see these git checkout commands for step 'Checkout Repository':

+ REMOTE=git@gitlab.com:PATH/TO/PROJECT.git
+ REF=origin/develop
+ git init .
Initialized empty Git repository in /kubectl-build-deploy/git/.git/
+ git config remote.origin.url git@gitlab.com:PATH/TO/PROJECT.git
+ git fetch --depth=10 --tags --progress git@gitlab.com:PATH/TO/PROJECT.git '+refs/heads/*:refs/remotes/origin/*'
+ git checkout --force origin/develop
Note: switching to 'origin/develop'.
...
HEAD is now at a2770406 Merge branch 'feature/branch-containing-docker-compose-changes' into 'develop'
+ git submodule update --init --recursive --jobs=6
+ [[ -n '' ]]
+ '[' '!' -f .lagoon.yml ']'
++ cat .lagoon.yml
++ shyaml get-value environment_variables.git_sha false
+ INJECT_GIT_SHA=false
+ '[' false == true ']'
+ LAGOON_GIT_SHA=0000000000000000000000000000000000000000

Expected behavior

We expect a checkout of the revision which was used during the deployment to develop to be used for the configuration files (.lagoon.yml and docker-compose.yml) instead of the latest version of these files in the branch.

In this case I also expect a the Git checkout HEAD to be at 2031482a instead of a2770406

Screenshots

N/A

Additional context

N/A

smlx commented 6 months ago

Possibly related to https://github.com/uselagoon/build-deploy-tool/issues/229