Skip to content

Commit dce48f8

Browse files
Mathieudewetdunglas
authored andcommitted
fix travis (#32)
* fix travis * WIP use deploy * Manage master deploy only * Add some documentation * Add some configuration * fix helm install * Test on a dev branch * Add some documentation and fix bucket creation * Fix directory name and make deploy.sh executable * fix gcloud config * Add missing skip cleanup in travis deploy stage * fix * exit on missing environment variable * Update * Update * Update * Update * Update * configure gcloud sooner in order that bucket creation can work * Update * Test if empty env var are displayed * Update deploy script to feet the branch naming process * Add todo * reset config for master deployment * Remove useless static ip * Update deploy script to feet the branch naming process * Try in dev mode * Add documentation, fix xdebug removing, update management of IPs and DNS for multi branch * Do not deploy on pull request on master branch * start the configuration of circle CI and check which CI is choose to deploy * test circle CI * move some environment variables in a script file * test env var circleci * test without filters * try to disable macos * wording * Choose machine between machine and docker executor type * Use command to avoid duplicate instructions * Use command to avoid duplicate instructions * Use command to avoid duplicate instructions * Fix use of formatbranch command * Fix use of formatbranch command * Fix use of formatbranch command * Fix use of formatbranch command * Fix use of formatbranch command * move some script instructions in sh files to improve reusability and test failure while lack of circleCI environment variables declaration * Check current directory and stuff in it * Check current directory and stuff in it * Check current directory and stuff in it * Check env var are load from env.sh file * Reset machine executor type * Fix directories not imported * Fix directories not imported * Fix directories not imported * Check env var form env.sh are loaded * Check env var form env.sh are loaded * Check env var form env.sh are loaded * Check env var form env.sh are loaded * Check env var form env.sh are loaded * Check env var form env.sh are loaded * Make test.sh executable and add missing end of file line to it * move some script instructions in sh files to improve reusability and improve deploy script * move some script instructions in sh files to improve reusability and improve deploy script * move some script instructions in sh files to improve reusability and improve deploy script * move some script instructions in sh files to improve reusability and improve deploy script * move some script instructions in sh files to improve reusability and improve deploy script * Wording to be more relevant * Wording to be more relevant * test * test * test * test * test * Change executor to use default circleCI running ubuntu with docker and cocker-compose ready to use * install npm * install npm * install npm * install npm * upgrade docker compose to be able to use 3.4 version file * Set circleCI machine image to one with Docker Engine version enable to support docker compose 3.4 version file * Set circleCI machine image to one with Docker Engine version enable to support docker compose 3.4 version file * wording to check when test are done * wording to check when test are done * wording to check when test are done * Removing circleCI files * Move test.sh in script stage * move some script instructions in sh files to improve reusability and improve before_deploy script * Add missing new line * Add missing new line * Check TRAVIS_PULL_REQUEST eenv var value * Skip check on environment variables for pull request * Wording and adding missing new end of file line
1 parent 588b868 commit dce48f8

File tree

6 files changed

+211
-58
lines changed

6 files changed

+211
-58
lines changed

.travis.yml

Lines changed: 101 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: php
22

33
dist: trusty
4+
45
sudo: required
56

67
services:
@@ -12,74 +13,116 @@ cache:
1213
- admin/node_modules
1314
- client/node_modules
1415

16+
# If you want to use multi branch deployment or branch naming, set MULTI_BRANCH value to 1 and set your DEPLOYMENT_BRANCH.
17+
# Don't forget to change the repo name to fit your needs.
18+
# If you need explanation about Parameter expansion, just see https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
19+
# TODO change the name of the service account to CI_SERVICE_ACCOUNT here, in GCP and in CI repositories env var in order to improve reusability and be able to use before_install.sh script in before_install stage.
1520
env:
1621
global:
17-
- APP_ENV=prod
18-
- KUBERNETES_ENV=prod
22+
- BRANCH=${TRAVIS_BRANCH}
23+
- BRANCH=`echo $BRANCH | sed -E "s/\//-/g"`
24+
- BRANCH=${BRANCH,,}
25+
- CI_SERVICE_ACCOUNT=${TRAVIS_SERVICE_ACCOUNT}
1926

27+
# Check that all needed travis environment variables are set.
28+
# When working in dev branchs we don't want to override the master builds so we need to define à DEV_ADMIN_BUCKET and a DEV_CLIENT_BUCKET.
29+
# If you really want branch naming, you can instead create buckets on the fly using subdomains e.g gs://${BRANCH}.you-domain.com
2030
before_install:
21-
- |
22-
if [ TRAVIS_BRANCH = "master" ] && [ $TRAVIS_REPO_SLUG = "api-platform/demo" ]; then
23-
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash -s -- --version v2.9.1;
24-
else
25-
KUBERNETES_ENV=staging;
26-
exit 0;
27-
fi
31+
- ./ci/before_install.sh
32+
- ./ci/env.sh
2833

2934
before_script:
35+
- phpenv config-rm xdebug.ini
3036
- sudo service mysql stop
3137
- sudo service postgresql stop
38+
- curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash -s -- --version v2.9.1;
3239
- npm install -g react-scripts
3340
- while sudo lsof -Pi :5432 -sTCP:LISTEN -t; do sleep 1; done
3441

3542
script:
36-
- docker-compose up -d
37-
- helm lint api/helm/api/
38-
- sleep 20
39-
- docker-compose exec php composer install -o -n
40-
- docker-compose exec php bin/console security:check
41-
- docker-compose exec php bin/console doctrine:schema:validate --skip-sync
42-
- docker-compose exec php bin/console doctrine:schema:drop --force
43-
- docker-compose exec php bin/console doctrine:schema:create
44-
- docker-compose exec php bin/console hautelook:fixtures:load -n
45-
- docker-compose exec php bin/console doctrine:schema:drop --env=test --force
46-
- docker-compose exec php bin/console cache:warmup --env=test
47-
- docker-compose exec php bin/behat
48-
- curl http://localhost
49-
- curl http://localhost:81
50-
- curl http://localhost:8080
51-
- curl http://localhost:8081
52-
- curl -k https://localhost
53-
- curl -k https://localhost:444
54-
- curl -k https://localhost:8443
55-
- curl -k https://localhost:8444
43+
- ./ci/test.sh
44+
45+
# Get kubectl and make it executable
46+
# Create the travis service account access file from travis environment variables
47+
# Connect to the project as travis service account by gcloud using the travis service account access file we just created above and configure project.
48+
# Create the needed bucket in which to push builds.
49+
before_deploy:
50+
- ./ci/before_deploy.sh
51+
- |
52+
if [[ "${MULTI_BRANCH}" == "0" && "${CURRENT_CI}" == "travis" ]]; then
53+
gsutil mb -p ${PROJECT_ID} -l eu gs://${ADMIN_BUCKET} || echo "Admin bucket exists";
54+
gsutil mb -p ${PROJECT_ID} -l eu gs://${CLIENT_BUCKET} || echo "Client bucket exists";
55+
elif [[ "${CURRENT_CI}" == "travis" ]]
56+
then
57+
gsutil mb -p ${PROJECT_ID} -l eu gs://${DEV_ADMIN_BUCKET} || echo "Dev admin bucket exists"
58+
gsutil mb -p ${PROJECT_ID} -l eu gs://${DEV_CLIENT_BUCKET} || echo "Dev client bucket exists"
59+
fi;
60+
61+
# Deploy images and buckets according to the current context, create or update Kubenetes release with updated informations.
62+
deploy:
63+
- provider: ci
64+
script: bash ci/deploy.sh
65+
skip_cleanup: true
66+
on:
67+
branch: ${DEPLOYMENT_BRANCH}
68+
repo: ${REPOSITORY}
69+
condition: "$MULTI_BRANCH == 0 && $TRAVIS_PULL_REQUEST == 'false' && CURRENT_CI == 'travis'"
70+
- provider: ci
71+
script: bash ci/deploy.sh
72+
skip_cleanup: true
73+
on:
74+
repo: ${REPOSITORY}
75+
condition: "$MULTI_BRANCH == 1 && CURRENT_CI == 'travis'"
76+
- provider: gcs
77+
access_key_id:
78+
secure: eSJfigRfZp7bwMBT61tes4NZZR5UnPSACWuD3seeLyMMflvfEiQBT30kMyQkcIA19cYUWuzCmdaUDGuphj8KrkPOfIqoPaG5ZM/zFbjgtJs3nNmpMt2GW/y5YFSqJR7ha0TYCUpPq9UonxEB/sdcifS7JRS0PmeEotZbcKMGmiCzDnFR8fNbDC1w1XZEfFoV+xtBYJCCDsZpPVjt+GXI+3OX31qnRCMv89aPU2lgmbUaF3oM+Bxc+9jQPEUmMKzOXt1AlIscJgkjyOIPTU9R1TsYtSNGzCxhEj2EtBdbtr2SKLdvJCaxABDtg6c0DOZSRSB5FP2kjLXm2TmtnFyn04R2RS7Cp3F5tueSpiK/51rI6oPc66OYMtWSINMhQzzWTiAdkBx2sekO9InbBgJMJgbcWt5nRvtzS/4mbCiDJxM+H4LuJHaqeCdDqZ51M1mf1HBh0diKIEn0o86fzUlPBtLZBLo/PCqGsJnLF+7VkG0AHExuJCSx8QHXfvP40+D3LtameHopx0lK+L8CMWwRzGJ5SDzzpfqoWZxwyzZjEvLzOdChWRb9jqPQDC1H48SFhsQt/eiwz0ZQq4v8I8DqQ3NkECYBoVgO7ozGN/pnqYK3i8xRnA47dGvSZrxQB32Eq0mkF6s8Rk7Xt6dI5ppNqdzjrCK2ZWijcGjBIQ769gQ=
79+
secret_access_key:
80+
secure: O4nNU4GlxBpnp1lJEEZKm0R3iUhK2V6qpu2JTxI4Vip6E5oAvXWJBc8keT75vbodRG2yYgmCf4HZhDnZRso6B7zY1SbE+oJjS6/jWM/Qkynf4qJ2/5NRvxjTuQsp99eqmclQ9J5CwhU690ZSZgC8eFaGN5Dwa2yJu5kBZHeUiDQgO3o3n1a2YCHBnOwQy7O7h6wj6d3iLThpfpdpLheqLF0DQ/c593Yy5mQgZRZkuqhLGWe94h8WyUtzJCmmYVP+XKNxbNKysCpD6zUulVTQ4XBYf5Z8kI2pAEP8UsTjqLZBjKdpyYqxoigyoL78hgs7KrYUBcCKW9qUsjRdXgNrsVvLYBQ+kau4eoFo4cmwlf3U37+HK1WENiLG6O3hHnu/n8b4AL2NaQPnsFWsWG1nrbfbPZ3j+Xvn6wJJWGkitUjahKFREcHSAFl5+jMqXULpTYP8X4ZkOYZ8M5V+1VhhSzqOH0lqsVYyDZbFIWf9UQJn51cNKBakULVWHvFMIlIMo4vULiXX7r4lWfY5FCYdABiOPADW2xuMg9++etlAcU4fpBl4Kf9GqWIs4XGmrVqJ9P5Jjto3J4bHyfF32v7HWC6vdwp81nvFHabMYj4AS9gmn6/90BQKEkN2OF43oRKsmq+IwFqt2HqMt7CakIYvdj5oQMu0j5lMY7JuYh1k2Ds=
81+
bucket: ${ADMIN_BUCKET}
82+
skip_cleanup: true
83+
acl: public-read
84+
local-dir: admin/build
85+
on:
86+
branch: ${DEPLOYMENT_BRANCH}
87+
repo: ${REPOSITORY}
88+
condition: "$MULTI_BRANCH == 0 && $TRAVIS_PULL_REQUEST == 'false' && CURRENT_CI == 'travis'"
89+
- provider: gcs
90+
access_key_id:
91+
secure: eSJfigRfZp7bwMBT61tes4NZZR5UnPSACWuD3seeLyMMflvfEiQBT30kMyQkcIA19cYUWuzCmdaUDGuphj8KrkPOfIqoPaG5ZM/zFbjgtJs3nNmpMt2GW/y5YFSqJR7ha0TYCUpPq9UonxEB/sdcifS7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HvFMIlIMo4vULiXX7r4lWfY5FCYdABiOPADW2xuMg9++etlAcU4fpBl4Kf9GqWIs4XGmrVqJ9P5Jjto3J4bHyfF32v7HWC6vdwp81nvFHabMYj4AS9gmn6/90BQKEkN2OF43oRKsmq+IwFqt2HqMt7CakIYvdj5oQMu0j5lMY7JuYh1k2Ds=
94+
bucket: ${DEV_ADMIN_BUCKET}
95+
skip_cleanup: true
96+
acl: public-read
97+
local-dir: admin/build
98+
on:
99+
branch: ${TRAVIS_BRANCH}
100+
repo: ${REPOSITORY}
101+
condition: "$MULTI_BRANCH == 1 && CURRENT_CI == 'travis'"
102+
- provider: gcs
103+
access_key_id:
104+
secure: eSJfigRfZp7bwMBT61tes4NZZR5UnPSACWuD3seeLyMMflvfEiQBT30kMyQkcIA19cYUWuzCmdaUDGuphj8KrkPOfIqoPaG5ZM/zFbjgtJs3nNmpMt2GW/y5YFSqJR7ha0TYCUpPq9UonxEB/sdcifS7JRS0PmeEotZbcKMGmiCzDnFR8fNbDC1w1XZEfFoV+xtBYJCCDsZpPVjt+GXI+3OX31qnRCMv89aPU2lgmbUaF3oM+Bxc+9jQPEUmMKzOXt1AlIscJgkjyOIPTU9R1TsYtSNGzCxhEj2EtBdbtr2SKLdvJCaxABDtg6c0DOZSRSB5FP2kjLXm2TmtnFyn04R2RS7Cp3F5tueSpiK/51rI6oPc66OYMtWSINMhQzzWTiAdkBx2sekO9InbBgJMJgbcWt5nRvtzS/4mbCiDJxM+H4LuJHaqeCdDqZ51M1mf1HBh0diKIEn0o86fzUlPBtLZBLo/PCqGsJnLF+7VkG0AHExuJCSx8QHXfvP40+D3LtameHopx0lK+L8CMWwRzGJ5SDzzpfqoWZxwyzZjEvLzOdChWRb9jqPQDC1H48SFhsQt/eiwz0ZQq4v8I8DqQ3NkECYBoVgO7ozGN/pnqYK3i8xRnA47dGvSZrxQB32Eq0mkF6s8Rk7Xt6dI5ppNqdzjrCK2ZWijcGjBIQ769gQ=
105+
secret_access_key:
106+
secure: O4nNU4GlxBpnp1lJEEZKm0R3iUhK2V6qpu2JTxI4Vip6E5oAvXWJBc8keT75vbodRG2yYgmCf4HZhDnZRso6B7zY1SbE+oJjS6/jWM/Qkynf4qJ2/5NRvxjTuQsp99eqmclQ9J5CwhU690ZSZgC8eFaGN5Dwa2yJu5kBZHeUiDQgO3o3n1a2YCHBnOwQy7O7h6wj6d3iLThpfpdpLheqLF0DQ/c593Yy5mQgZRZkuqhLGWe94h8WyUtzJCmmYVP+XKNxbNKysCpD6zUulVTQ4XBYf5Z8kI2pAEP8UsTjqLZBjKdpyYqxoigyoL78hgs7KrYUBcCKW9qUsjRdXgNrsVvLYBQ+kau4eoFo4cmwlf3U37+HK1WENiLG6O3hHnu/n8b4AL2NaQPnsFWsWG1nrbfbPZ3j+Xvn6wJJWGkitUjahKFREcHSAFl5+jMqXULpTYP8X4ZkOYZ8M5V+1VhhSzqOH0lqsVYyDZbFIWf9UQJn51cNKBakULVWHvFMIlIMo4vULiXX7r4lWfY5FCYdABiOPADW2xuMg9++etlAcU4fpBl4Kf9GqWIs4XGmrVqJ9P5Jjto3J4bHyfF32v7HWC6vdwp81nvFHabMYj4AS9gmn6/90BQKEkN2OF43oRKsmq+IwFqt2HqMt7CakIYvdj5oQMu0j5lMY7JuYh1k2Ds=
107+
bucket: ${CLIENT_BUCKET}
108+
skip_cleanup: true
109+
acl: public-read
110+
local-dir: client/build
111+
on:
112+
branch: ${DEPLOYMENT_BRANCH}
113+
repo: ${REPOSITORY}
114+
condition: "$MULTI_BRANCH == 0 && $TRAVIS_PULL_REQUEST == 'false' && CURRENT_CI == 'travis'"
115+
- provider: gcs
116+
access_key_id:
117+
secure: eSJfigRfZp7bwMBT61tes4NZZR5UnPSACWuD3seeLyMMflvfEiQBT30kMyQkcIA19cYUWuzCmdaUDGuphj8KrkPOfIqoPaG5ZM/zFbjgtJs3nNmpMt2GW/y5YFSqJR7ha0TYCUpPq9UonxEB/sdcifS7JRS0PmeEotZbcKMGmiCzDnFR8fNb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ABiOPADW2xuMg9++etlAcU4fpBl4Kf9GqWIs4XGmrVqJ9P5Jjto3J4bHyfF32v7HWC6vdwp81nvFHabMYj4AS9gmn6/90BQKEkN2OF43oRKsmq+IwFqt2HqMt7CakIYvdj5oQMu0j5lMY7JuYh1k2Ds=
120+
bucket: ${DEV_CLIENT_BUCKET}
121+
skip_cleanup: true
122+
acl: public-read
123+
local-dir: client/build
124+
on:
125+
branch: ${TRAVIS_BRANCH}
126+
repo: ${REPOSITORY}
127+
condition: "$MULTI_BRANCH == 1 && CURRENT_CI == 'travis'"
56128

57-
# TODO: Keep looking to https://github.com/kubernetes/kubernetes/pull/64034 as it is in an experimental state in order to use "wait" with new implementation (to replace sleep 60).
58-
after_success:
59-
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
60-
- chmod +x ./kubectl
61-
- sudo mv ./kubectl /usr/local/bin/kubectl
62-
- echo -n ${TRAVIS_SERVICE_ACCOUNT_KEY} | base64 -d > travis-service-account.json
63-
- gcloud auth activate-service-account ${TRAVIS_SERVICE_ACCOUNT} --key-file travis-service-account.json --project=${PROJECT_NAME}
64-
- gcloud config set compute/zone europe-west1-c
65-
- gcloud config set project ${PROJECT_NAME}
66-
- gcloud container clusters get-credentials api-platform-demo --zone europe-west1-c --project ${PROJECT_NAME}
67-
- helm init --upgrade
68-
- kubectl delete namespace $(kubectl get namespaces -l app=api-demo -o jsonpath="{.items[0].metadata.name}" --ignore-not-found) --ignore-not-found
69-
- helm dependencies update ./api/helm/api
70-
- docker build --pull -t eu.gcr.io/${PROJECT_NAME}/php -t eu.gcr.io/${PROJECT_NAME}/php:latest api --target api_platform_php
71-
- docker build --pull -t eu.gcr.io/${PROJECT_NAME}/nginx -t eu.gcr.io/${PROJECT_NAME}/nginx:latest api --target api_platform_nginx
72-
- docker build --pull -t eu.gcr.io/${PROJECT_NAME}/varnish -t eu.gcr.io/${PROJECT_NAME}/varnish:latest api --target api_platform_varnish
73-
- gcloud docker -- push eu.gcr.io/${PROJECT_NAME}/php:latest
74-
- gcloud docker -- push eu.gcr.io/${PROJECT_NAME}/nginx:latest
75-
- gcloud docker -- push eu.gcr.io/${PROJECT_NAME}/varnish:latest
76-
- helm install --wait --namespace=${TRAVIS_COMMIT} ./api/helm/api --set php.repository=eu.gcr.io/${PROJECT_NAME}/php --set nginx.repository=eu.gcr.io/${PROJECT_NAME}/nginx --set varnish.repository=eu.gcr.io/${PROJECT_NAME}/varnish --set secret=${APP_SECRET} --set postgresUser=${DATABASE_USER},postgresPassword="${DATABASE_PASSWORD}",postgresDatabase=${DATABASE_NAME} --set postgresql.persistence.enabled=true --set corsAllowOrigin='*'
77-
- sleep 60
78-
- kubectl exec -it $(kubectl --namespace=${TRAVIS_COMMIT} get pods -l app=api-php -o jsonpath="{.items[0].metadata.name}") --namespace=${TRAVIS_COMMIT} -- ash -c 'export APP_ENV=dev && composer install -n && bin/console d:s:u --force --env=dev && bin/console hautelook:fixtures:load -n && APP_ENV=prod composer --no-dev install --classmap-authoritative && bin/console d:s:u --env=prod'
79-
- kubectl label namespace ${TRAVIS_COMMIT} app=api-demo
80-
- cd admin && REACT_APP_API_ENTRYPOINT=http://demo-admin.api-platform.com yarn build --environment=prod
81-
- gsutil mb -l europe-west1 -p api-platform-demo gs://demo-admin.api-platform.com
82-
- cd admin && gsutil cp -R build/* gs://demo-admin.api-platform.com/build
83-
- gsutil iam ch allUsers:objectViewer gs://demo-admin.api-platform.com
84-
- gsutil web set -m index.html gs://demo-admin.api-platform.com
85-
- gcloud auth revoke ${TRAVIS_SERVICE_ACCOUNT}

ci/before_deploy.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
4+
chmod +x ./kubectl
5+
sudo mv ./kubectl /usr/local/bin/kubectl
6+
echo -n ${CI_SERVICE_ACCOUNT} | base64 -d > travis-service-account.json
7+
gcloud auth activate-service-account ${CI_SERVICE_ACCOUNT} --key-file travis-service-account.json --project=${PROJECT_ID}
8+
gcloud config set compute/zone europe-west1-c
9+
gcloud config set core/project ${PROJECT_ID}
10+
gcloud container clusters get-credentials api-platform-demo --zone europe-west1-c --project ${PROJECT_ID}
11+
helm init --upgrade

ci/before_install.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $TRAVIS_PULL_REQUEST != 'false' ]]; then echo 'Skipping deployment for pull requests';
4+
else
5+
if [[ -z "${PROJECT_ID}" ]]; then echo 'PROJECT_ID is not defined in your travis environement variables.'; exit 1; fi
6+
if [[ -z "${ADMIN_BUCKET}" ]]; then echo 'ADMIN_BUCKET is not defined in your travis environement variables.'; exit 1; fi
7+
if [[ -z "${CLIENT_BUCKET}" ]]; then echo 'CLIENT_BUCKET is not defined in your travis environement variables.'; exit 1; fi
8+
if [[ -z "${CI_SERVICE_ACCOUNT}" ]]; then echo 'CI_SERVICE_ACCOUNT is not defined in your ci repository environement variables.'; exit 1; fi
9+
if [[ -z "${DATABASE_USER}" ]]; then echo 'DATABASE_USER is not defined in your travis environement variables.'; exit 1; fi
10+
if [[ -z "${DATABASE_PASSWORD}" ]]; then echo 'DATABASE_PASSWORD is not defined in your travis environement variables.'; exit 1; fi
11+
if [[ -z "${DATABASE_NAME}" ]]; then echo 'DATABASE_NAME is not defined in your travis environement variables.'; exit 1; fi
12+
if [[ -z "${DEV_ADMIN_BUCKET}" && MULTI_BRANCH == "1" ]]; then echo 'DEV_ADMIN_BUCKET is not defined in your travis environement variables.'; exit 1; fi
13+
if [[ -z "${DEV_CLIENT_BUCKET}" && MULTI_BRANCH == "1" ]]; then echo 'DEV_CLIENT_BUCKET is not defined in your travis environement variables.'; exit 1; fi
14+
fi

ci/deploy.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
4+
# Update dependencies and docker image end push them taking care to separate by repositories and branches.
5+
echo 'deploy script'
6+
helm dependencies update ./api/helm/api
7+
8+
# You can customize it to fit your needs, for example for branch naming e.g. PHP_REPOSITORY="eu.gcr.io/${PROJECT_ID}/php-${BRANCH}"
9+
if [[ ${BRANCH} == "master" ]]
10+
then
11+
export PHP_REPOSITORY="eu.gcr.io/${PROJECT_ID}/php";
12+
export NGINX_REPOSITORY="eu.gcr.io/${PROJECT_ID}/nginx";
13+
export VARNISH_REPOSITORY="eu.gcr.io/${PROJECT_ID}/varnish";
14+
export STATIC_IP="--set ingress.annotations.kubernetes.io/ingress.global-static-ip-name: ${STATIC_IP}";
15+
else
16+
export PHP_REPOSITORY="eu.gcr.io/${PROJECT_ID}/php-staging";
17+
export NGINX_REPOSITORY="eu.gcr.io/${PROJECT_ID}/nginx-staging";
18+
export VARNISH_REPOSITORY="eu.gcr.io/${PROJECT_ID}/varnish-staging";
19+
export STATIC_IP="";
20+
fi
21+
22+
# Build and push the docker images.
23+
docker build --pull -t ${PHP_REPOSITORY} -t ${PHP_REPOSITORY}:latest api --target api_platform_php;
24+
docker build --pull -t ${NGINX_REPOSITORY} -t ${NGINX_REPOSITORY}:latest api --target api_platform_nginx;
25+
docker build --pull -t ${VARNISH_REPOSITORY} -t ${VARNISH_REPOSITORY}:latest api --target api_platform_varnish;
26+
gcloud docker -- push ${PHP_REPOSITORY}:latest;
27+
gcloud docker -- push ${NGINX_REPOSITORY}:latest;
28+
gcloud docker -- push ${VARNISH_REPOSITORY}:latest;
29+
30+
# Perform a rolling update if a release in the given namespace ever exist, create one otherwise.
31+
# Be aware that we have the static ip for the master branch but it belongs to you to care about others.
32+
helm upgrade --install --reset-values --wait --force --namespace=${BRANCH} --recreate-pods demo ./api/helm/api STATIC_IP \
33+
--set php.repository=${PHP_REPOSITORY} \
34+
--set nginx.repository=${NGINX_REPOSITORY} \
35+
--set varnish.repository=${VARNISH_REPOSITORY} \
36+
--set secret=${APP_SECRET} \
37+
--set postgresUser=${DATABASE_USER},postgresPassword="${DATABASE_PASSWORD}",postgresDatabase=${DATABASE_NAME} --set postgresql.persistence.enabled=true;
38+
39+
kubectl exec -it $(kubectl --namespace=${BRANCH} get pods -l app=api-php -o jsonpath="{.items[0].metadata.name}") --namespace=${BRANCH} \
40+
-- ash -c'export APP_ENV=dev && composer install -n && bin/console d:s:u --force --env=dev && bin/console hautelook:fixtures:load -n && APP_ENV=prod composer --no-dev install --classmap-authoritative && bin/console d:s:u --env=prod';
41+
42+
# For the master branch the REACT_APP_API_ENTRYPOINT will be the URL plug on your static IP.
43+
# For Dev branchs you can use the IP retrievable by the kubectl get ingress command.
44+
if [[ ${BRANCH} == "master" ]]
45+
then
46+
export API_ENTRYPOINT=${PROD_DNS};
47+
else
48+
export API_ENTRYPOINT=$(kubectl --namespace `echo ${BRANCH}` get ingress -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}');
49+
fi
50+
51+
52+
cd admin && yarn && REACT_APP_API_ENTRYPOINT=https://${API_ENTRYPOINT} yarn build --environment=prod;
53+
cd ../client && yarn && REACT_APP_ADMIN_HOST_HTTPS=https://${ADMIN_BUCKET} REACT_APP_ADMIN_HOST_HTTP=http://${ADMIN_BUCKET} REACT_APP_API_CACHED_HOST_HTTPS=https://${API_ENTRYPOINT} REACT_APP_API_CACHED_HOST_HTTP=http://${API_ENTRYPOINT} yarn build --environment=prod;

ci/env.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# Choose the CI you want to run the deployments.
4+
# Both CI will make tests but only the one specified will deploy.
5+
# Current available choices are travis and circleci.
6+
export CURRENT_CI='travis'
7+
export MULTI_BRANCH=0
8+
export REPOSITORY='api-platform/demo'
9+
export DEPLOYMENT_BRANCH'=master'
10+
export PROD_DNS='demo.api-platform.com'

0 commit comments

Comments
 (0)