Skip to content

Feature/update demo deployment #26

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

Merged
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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTAINER_REGISTRY_BASE=quay.io/api-platform
CONTAINER_REGISTRY_BASE=eu.gcr.io/api-platform-demo
53 changes: 48 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
language: php

dist: trusty
sudo: required

services:
Expand All @@ -9,20 +12,30 @@ cache:
- admin/node_modules
- client/node_modules

env:
global:
- APP_ENV=prod
- KUBERNETES_ENV=prod

before_install:
- |
if [ TRAVIS_BRANCH = "master" ] && [ $TRAVIS_REPO_SLUG = "api-platform/demo" ]; then
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash -s -- --version v2.9.1;
else
KUBERNETES_ENV=staging;
exit 0;
fi

before_script:
- sudo service mysql stop
- sudo service postgresql stop
- wget https://kubernetes-helm.storage.googleapis.com/helm-v2.6.1-linux-amd64.tar.gz
- tar xzf helm-v2.6.1-linux-amd64.tar.gz
- npm install -g react-scripts
- while sudo lsof -Pi :5432 -sTCP:LISTEN -t; do sleep 1; done

script:
- docker-compose up -d
- linux-amd64/helm lint api/helm/api/
- helm lint api/helm/api/
- sleep 20
- sh -c "cd admin && PUBLIC_URL="/api-demo-admin-test" yarn install && yarn build"
- sh -c "cd client && PUBLIC_URL="/api-demo-client-test" yarn install && yarn build"
- docker-compose exec php composer install -o -n
- docker-compose exec php bin/console security:check
- docker-compose exec php bin/console doctrine:schema:validate --skip-sync
Expand All @@ -40,3 +53,33 @@ script:
- curl -k https://localhost:444
- curl -k https://localhost:8443
- curl -k https://localhost:8444

# 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).
after_success:
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- sudo mv ./kubectl /usr/local/bin/kubectl
- echo -n ${TRAVIS_SERVICE_ACCOUNT_KEY} | base64 -d > travis-service-account.json
- gcloud auth activate-service-account ${TRAVIS_SERVICE_ACCOUNT} --key-file travis-service-account.json --project=${PROJECT_NAME}
- gcloud config set compute/zone europe-west1-c
- gcloud config set project ${PROJECT_NAME}
- gcloud container clusters get-credentials api-platform-demo --zone europe-west1-c --project ${PROJECT_NAME}
- helm init --upgrade
- kubectl delete namespace $(kubectl get namespaces -l app=api-demo -o jsonpath="{.items[0].metadata.name}" --ignore-not-found) --ignore-not-found
- helm dependencies update ./api/helm/api
- docker build --pull -t eu.gcr.io/${PROJECT_NAME}/php -t eu.gcr.io/${PROJECT_NAME}/php:latest api --target api_platform_php
- docker build --pull -t eu.gcr.io/${PROJECT_NAME}/nginx -t eu.gcr.io/${PROJECT_NAME}/nginx:latest api --target api_platform_nginx
- docker build --pull -t eu.gcr.io/${PROJECT_NAME}/varnish -t eu.gcr.io/${PROJECT_NAME}/varnish:latest api --target api_platform_varnish
- gcloud docker -- push eu.gcr.io/${PROJECT_NAME}/php:latest
- gcloud docker -- push eu.gcr.io/${PROJECT_NAME}/nginx:latest
- gcloud docker -- push eu.gcr.io/${PROJECT_NAME}/varnish:latest
- 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='*'
- sleep 60
- 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'
- kubectl label namespace ${TRAVIS_COMMIT} app=api-demo
- cd admin && REACT_APP_API_ENTRYPOINT=http://demo-admin.api-platform.com yarn build --environment=prod
- gsutil mb -l europe-west1 -p api-platform-demo gs://demo-admin.api-platform.com
- cd admin && gsutil cp -R build/* gs://demo-admin.api-platform.com/build
- gsutil iam ch allUsers:objectViewer gs://demo-admin.api-platform.com
- gsutil web set -m index.html gs://demo-admin.api-platform.com
- gcloud auth revoke ${TRAVIS_SERVICE_ACCOUNT}
1 change: 1 addition & 0 deletions api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
Expand Down
14 changes: 14 additions & 0 deletions api/helm/api/templates/api-plateform-demo-ip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: api-platform-demo-ip
labels:
app: {{ template "name" . }}-ip
spec:
type: NodePort
selector:
app: {{ template "name" . }}
tier: web
ports:
- port: 80
targetPort: 8080
9 changes: 5 additions & 4 deletions api/helm/api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,31 @@
env: prod
debug: '0'
secret: ChangeMe
corsAllowOrigin: http://example.com
corsAllowOrigin: '*'

php:
repository: gcr.io/test-api-platform/php
repository: eu.gcr.io/api-platform-demo-210115/php
tag: latest
pullPolicy: Always
replicaCount: 1

nginx:
repository: gcr.io/test-api-platform/nginx
repository: eu.gcr.io/api-platform-demo-210115/nginx
tag: latest
pullPolicy: Always
replicaCount: 1

varnish:
enabled: true
#url: https://example.com
repository: gcr.io/test-api-platform/varnish
repository: eu.gcr.io/api-platform-demo-210115/varnish
tag: latest
pullPolicy: Always
replicaCount: 1

ingress:
annotations:
kubernetes.io/ingress.global-static-ip-name: api-platform-demo-ip
# kubernetes.io/ingress.class: gce
# kubernetes.io/tls-acme: "true"
tls:
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ services:
- api
volumes:
- ./api/docker/varnish/conf:/usr/local/etc/varnish:ro
tmpfs:
- /usr/local/var/varnish:exec
ports:
- "8081:80"

Expand Down