Skip to content

Commit

Permalink
use bitnami/postgresql image for db
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Jan 25, 2019
1 parent a406e4d commit 88955f9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ bin/console text eol=lf
LICENSE export-ignore
README.md export-ignore
update-deps.sh export-ignore
ci/bin/* binary
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cache:
env:
global:
- BRANCH=$TRAVIS_BRANCH
- RELEASE=demo-`echo $BRANCH | sed -E "s/\//-/g" | sed -e 's/\(.*\)/\L\1/'`
- RELEASE=`echo $BRANCH | sed -E "s/\//-/g" | sed -e 's/\(.*\)/\L\1/'`
- NAMESPACE=$RELEASE

before_script:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ environment variables in your CI:
* `PROJECT_ID`: GCP project id (i.e: `api-platform-demo-123456`)
* `CI_SERVICE_ACCOUNT`: GCP service account
* `CI_SERVICE_ACCOUNT_KEY`: GCP service account key
* `CF_API_KEY`: Cloudflare API key
* `CF_API_EMAIL`: Cloudflare email

**Important: do not check "_Display value in build log_"!**

Expand Down
6 changes: 6 additions & 0 deletions ci/before_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

set -e

# TODO Remove
export CF_API_KEY=$CLOUDFLARE_API_KEY
export CF_API_EMAIL=$CLOUDFLARE_API_EMAIL

# Check that all needed environment variables are set.
if [[ $TRAVIS_PULL_REQUEST != 'false' ]]; then echo 'Skipping deployment for pull requests';
else
if [[ -z $PROJECT_ID ]]; then echo 'PROJECT_ID is not defined in your travis environment variables.'; fi
if [[ -z $CI_SERVICE_ACCOUNT ]]; then echo 'CI_SERVICE_ACCOUNT is not defined in your ci repository environment variables.'; fi
if [[ -z $CI_SERVICE_ACCOUNT_KEY ]]; then echo 'CI_SERVICE_ACCOUNT_KEY is not defined in your ci repository environment variables.'; fi
if [[ -z $CF_API_KEY ]]; then echo 'CF_API_KEY is not defined in your ci repository environment variables.'; fi
if [[ -z $CF_API_EMAIL ]]; then echo 'CF_API_EMAIL is not defined in your ci repository environment variables.'; fi
fi

# To enable blackfire, set the BLACKFIRE_SERVER_ID and BLACKFIRE_SERVER_TOKEN variables.
Expand Down
File renamed without changes.
27 changes: 16 additions & 11 deletions ci/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ gsutil mb -p $PROJECT_ID -l eu gs://$ADMIN_BUCKET || echo "Admin bucket exists"
gsutil mb -p $PROJECT_ID -l eu gs://$CLIENT_BUCKET || echo "Client bucket exists"

# Build and push the docker images.
docker build --build-arg INSTALL_BLACKFIRE=$BLACKFIRE_ENABLED --pull -t $PHP_REPOSITORY api --target api_platform_php
docker build --pull -t $NGINX_REPOSITORY api --target api_platform_nginx
docker build --pull -t $VARNISH_REPOSITORY api --target api_platform_varnish
gcloud docker -- push $PHP_REPOSITORY
gcloud docker -- push $NGINX_REPOSITORY
gcloud docker -- push $VARNISH_REPOSITORY
docker build --build-arg INSTALL_BLACKFIRE=$BLACKFIRE_ENABLED --pull -t $PHP_REPOSITORY:$TAG api --target api_platform_php
docker build --pull -t $NGINX_REPOSITORY:$TAG api --target api_platform_nginx
docker build --pull -t $VARNISH_REPOSITORY:$TAG api --target api_platform_varnish
gcloud docker -- push $PHP_REPOSITORY:$TAG
gcloud docker -- push $NGINX_REPOSITORY:$TAG
gcloud docker -- push $VARNISH_REPOSITORY:$TAG

if [[ $BRANCH != $DEPLOYMENT_BRANCH ]]
then
Expand All @@ -39,8 +39,8 @@ helm upgrade --install --reset-values --force --namespace=${NAMESPACE} --recreat
--set ingress.hosts.api.host=$API_ENTRYPOINT \
--set ingress.hosts.mercure.host=$MERCURE_ENTRYPOINT \
--set mercure.subscribeUrl="${MERCURE_ENTRYPOINT}/hub" \
--set external-dns.cloudflare.apiKey=$CLOUDFLARE_API_KEY \
--set external-dns.cloudflare.email=$CLOUDFLARE_API_EMAIL \
--set external-dns.cloudflare.apiKey=$CF_API_KEY \
--set external-dns.cloudflare.email=$CF_API_EMAIL \
--set corsAllowOrigin=$CORS_ALLOW_ORIGIN \
--set mercure.corsAllowOrigin=$CORS_ALLOW_ORIGIN \
--set trustedHosts=$TRUSTED_HOSTS \
Expand All @@ -50,18 +50,23 @@ helm upgrade --install --reset-values --force --namespace=${NAMESPACE} --recreat
echo "Waiting for the PHP container to be up and ready..."
sleep 60
kubectl exec --namespace=$NAMESPACE -it $(kubectl --namespace=$NAMESPACE get pods -l app=api-php -o jsonpath="{.items[0].metadata.name}") \
-- sh -c 'APP_ENV=dev composer install -n && bin/console d:s:u --force -e prod && bin/console h:f:l -n -e dev && APP_ENV=prod composer --no-dev install --classmap-authoritative && echo "${API_ENTRYPOINT} deployed"'
-- sh -c 'APP_ENV=dev composer install -n && bin/console d:s:u --force -e prod && bin/console h:f:l -n -e dev && APP_ENV=prod composer --no-dev install --classmap-authoritative'
echo "API successfully deployed to ${API_ENTRYPOINT}"
echo "Mercure successfully deployed to ${MERCURE_ENTRYPOINT}"

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
# Build & deploy the admin.
cd admin && CI=false yarn install && REACT_APP_API_ENTRYPOINT=https://$API_ENTRYPOINT CI=false yarn build --environment=prod && cd ..
gsutil rsync -R admin/build gs://$ADMIN_BUCKET
gsutil web set -m index.html -e index.html gs://$ADMIN_BUCKET
gsutil iam ch allUsers:objectViewer gs://$ADMIN_BUCKET
flarectl dns c --zone=$DOMAIN --name=$ADMIN_BUCKET --type=CNAME --content=c.storage.googleapis.com --proxy
$DIR/bin/flarectl dns c --zone=$DOMAIN --name=$ADMIN_BUCKET --type=CNAME --content=c.storage.googleapis.com --proxy
echo "Admin successfully deployed to ${ADMIN_ENTRYPOINT}"

# Build & deploy the client.
cd client && yarn install && REACT_APP_ADMIN_HOST_HTTPS=https://$ADMIN_BUCKET REACT_APP_API_CACHED_HOST_HTTPS=https://$API_ENTRYPOINT REACT_APP_API_ENTRYPOINT=https://$API_ENTRYPOINT yarn build --environment=prod && cd ..
gsutil rsync -R client/build gs://$CLIENT_BUCKET
gsutil web set -m index.html -e index.html gs://$CLIENT_BUCKET
gsutil iam ch allUsers:objectViewer gs://$CLIENT_BUCKET
flarectl dns c --zone=$DOMAIN --name=$CLIENT_BUCKET --type=CNAME --content=c.storage.googleapis.com --proxy
$DIR/bin/flarectl dns c --zone=$DOMAIN --name=$CLIENT_BUCKET --type=CNAME --content=c.storage.googleapis.com --proxy
echo "Client successfully deployed to ${CLIENT_ENTRYPOINT}"
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ services:

db:
# In production, you may want to use a managed database service
image: postgres:9.6-alpine
image: bitnami/postgresql
environment:
- POSTGRES_DB=api
- POSTGRES_USER=api-platform
- POSTGRESQL_DATABASE=api
- POSTGRESQL_USERNAME=api-platform
# You should definitely change the password in production
- POSTGRES_PASSWORD=!ChangeMe!
- POSTGRESQL_PASSWORD=!ChangeMe!
volumes:
- db-data:/var/lib/postgresql/data:rw
# You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
Expand Down

0 comments on commit 88955f9

Please sign in to comment.