I'm trying to setup a continuous deployment pipeline in bitbucket pipelines. The following is the pipelines code:
- export GCLOUD_API_KEY_FILE=~/.gcloud-api-key.json- echo $GOOGLE_CONTAINER_REGISTRY_KEY | base64 -d > $GCLOUD_API_KEY_FILE- gcloud auth activate-service-account --key-file $GCLOUD_API_KEY_FILE- gcloud auth configure-docker --quiet - export DOCKER_IMAGE_NAME=eu.gcr.io/project-name/image-name:$BITBUCKET_COMMIT- docker build -t $DOCKER_IMAGE_NAME -f docker/beta/Dockerfile .- docker push $DOCKER_IMAGE_NAME- gcloud config set project project-name- gcloud config set compute/zone europe-west3-a- gcloud compute instances update-container instance-name --container-image $DOCKER_IMAGE_NAME- /bin/bash ./scripts/deploy/beta/test.shIn test.sh I check if the gcloud instance ssh is up, and if it is, I execute a post-deploy script:
test.sh
COUNTER=12POST_DEPLOY="docker exec klt-container-vgpx /application/scripts/deploy/beta/post-deploy.sh"while [ $COUNTER -gt 0 ]dogcloud compute ssh --verbosity=error --zone="europe-west3-a" "container-registry-and-compute@instance-name" --command="echo instance now up"if [ $? -eq 0 ]thengcloud compute ssh container-registry-and-compute@instance-name --verbosity=info --command="$POST_DEPLOY"exit 0fisleep 10sCOUNTER=$((COUNTER-1))doneecho "ERROR: VM instance SSH service is not available" exit 1post-deploy.sh
#!/bin/sh #Creates database, loads migrations and fixtures/application/bin/console doctrine:database:drop --if-exists --force --env=dev /application/bin/console doctrine:database:create --env=dev/application/bin/console doctrine:schema:create --env=dev/application/bin/console doctrine:migrations:migrate --no-interaction --env=dev --quiet /application/bin/console doctrine:fixtures:load --no-interaction --append --env=devThe problem is that the migrations and fixtures are not being loaded. Bitbucket pipelines runs successfully but without executing all the commands of the script. It just creates the database and the schema.
If I launch the pipeline without the gcloud compute instances update-container command, the post-deploy.sh script executes successfully every single command.
Also works successfully if I add a 120s sleep after the gcloud compute instances update-container command, so I think that maybe all services are not loaded yet when the script is executed, but the problem then is, why is the database and the schema being created? I can see the following logs in bitbucket pipelines:
Dropped database `name-db` for connection named defaultCreated database `name-db` for connection named default! [CAUTION] This operation should not be executed in a production environment! Creating database schema...