Skip to content

Commit 588b868

Browse files
Mathieudewetdunglas
authored andcommitted
Feature/update demo deployment (#26)
* Adds encrypted credentials for Travis * WIP * Remove irrelevant steps * test without PR * test without PR * Get service account credentials through encrypted env var * Wait release finish to deploy * Fix static ip * Fix static ip * Cleaning * Doesnt reinstall kubernetes on PRs * replay travis * Change GCR to european one * Add admin * Change cluster to more relevant one * change bucket * Check branch to deploy
1 parent 3a91ee1 commit 588b868

File tree

6 files changed

+71
-10
lines changed

6 files changed

+71
-10
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CONTAINER_REGISTRY_BASE=quay.io/api-platform
1+
CONTAINER_REGISTRY_BASE=eu.gcr.io/api-platform-demo

.travis.yml

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
language: php
2+
3+
dist: trusty
14
sudo: required
25

36
services:
@@ -9,20 +12,30 @@ cache:
912
- admin/node_modules
1013
- client/node_modules
1114

15+
env:
16+
global:
17+
- APP_ENV=prod
18+
- KUBERNETES_ENV=prod
19+
20+
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
28+
1229
before_script:
1330
- sudo service mysql stop
1431
- sudo service postgresql stop
15-
- wget https://kubernetes-helm.storage.googleapis.com/helm-v2.6.1-linux-amd64.tar.gz
16-
- tar xzf helm-v2.6.1-linux-amd64.tar.gz
1732
- npm install -g react-scripts
1833
- while sudo lsof -Pi :5432 -sTCP:LISTEN -t; do sleep 1; done
1934

2035
script:
2136
- docker-compose up -d
22-
- linux-amd64/helm lint api/helm/api/
37+
- helm lint api/helm/api/
2338
- sleep 20
24-
- sh -c "cd admin && PUBLIC_URL="/api-demo-admin-test" yarn install && yarn build"
25-
- sh -c "cd client && PUBLIC_URL="/api-demo-client-test" yarn install && yarn build"
2639
- docker-compose exec php composer install -o -n
2740
- docker-compose exec php bin/console security:check
2841
- docker-compose exec php bin/console doctrine:schema:validate --skip-sync
@@ -40,3 +53,33 @@ script:
4053
- curl -k https://localhost:444
4154
- curl -k https://localhost:8443
4255
- curl -k https://localhost:8444
56+
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}

api/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
}
4949
},
5050
"replace": {
51+
"symfony/polyfill-ctype": "*",
5152
"symfony/polyfill-iconv": "*",
5253
"symfony/polyfill-php71": "*",
5354
"symfony/polyfill-php70": "*",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: api-platform-demo-ip
5+
labels:
6+
app: {{ template "name" . }}-ip
7+
spec:
8+
type: NodePort
9+
selector:
10+
app: {{ template "name" . }}
11+
tier: web
12+
ports:
13+
- port: 80
14+
targetPort: 8080

api/helm/api/values.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,31 @@
55
env: prod
66
debug: '0'
77
secret: ChangeMe
8-
corsAllowOrigin: http://example.com
8+
corsAllowOrigin: '*'
99

1010
php:
11-
repository: gcr.io/test-api-platform/php
11+
repository: eu.gcr.io/api-platform-demo-210115/php
1212
tag: latest
1313
pullPolicy: Always
1414
replicaCount: 1
1515

1616
nginx:
17-
repository: gcr.io/test-api-platform/nginx
17+
repository: eu.gcr.io/api-platform-demo-210115/nginx
1818
tag: latest
1919
pullPolicy: Always
2020
replicaCount: 1
2121

2222
varnish:
2323
enabled: true
2424
#url: https://example.com
25-
repository: gcr.io/test-api-platform/varnish
25+
repository: eu.gcr.io/api-platform-demo-210115/varnish
2626
tag: latest
2727
pullPolicy: Always
2828
replicaCount: 1
2929

3030
ingress:
3131
annotations:
32+
kubernetes.io/ingress.global-static-ip-name: api-platform-demo-ip
3233
# kubernetes.io/ingress.class: gce
3334
# kubernetes.io/tls-acme: "true"
3435
tls:

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ services:
4444
- api
4545
volumes:
4646
- ./api/docker/varnish/conf:/usr/local/etc/varnish:ro
47+
tmpfs:
48+
- /usr/local/var/varnish:exec
4749
ports:
4850
- "8081:80"
4951

0 commit comments

Comments
 (0)