This document summarizes a presentation about deploying millions of emails per hour using cloud-based CI/CD practices. It discusses using App Engine and SendGrid for email delivery infrastructure, integrating CI (continuous integration) and CD (continuous delivery) with tools like Gitlab, Cloud Source Repositories, and Stackdriver Debugger. It also provides a demo of these practices and learning resources for email deliverability best practices, SendGrid documentation, and GCP services like Cloud Source Repositories and Stackdriver Debugger.
6. EDM 二三事 & 送信服務架構
Let’s start with the first set of slides 1
7. 寄送 Email 好簡單 - API Call
# Google App Engine Send Email example (Python)
from google.appengine.api import app_identity
from google.appengine.api import mail
def send_approved_mail(sender_address):
# [START send_mail]
mail.send_mail(sender=sender_address,
to="Albert Johnson <Albert.Johnson@example.com>",
subject="Your account has been approved",
body="""Dear Albert:
Your example.com account has been approved. You can now visit
http://www.example.com/ and sign in using your Google Account to
access new features.
Please let us know if you have any questions.
The example.com Team
""")
# [END send_mail]
send_approved_mail('{}@appspot.gserviceaccount.com'.format(app_identity.get_application_id()))
19. 我們所使用到的資源
AppEngine
BigQuery
CloudStorage
DataStore
CloudEndpoints
Sendgrid
A fast, economical and fully
managed data warehouse for
large-scale data analytics
BigQuery
Cloud Datastore is a highly-
scalable NoSQL database for
your web and mobile
applications.
DataStore
A powerful platform to build
web and mobile apps that
scale automatically.
App Engine
A Powerful, Simple and Cost
Effective Object Storage
Service.
Cloud Storage
Delivering your transactional
and marketing email through
one reliable platform.
Sendgrid
Create RESTful APIs on App
Engine accessible to iOS,
Android and Javascript
clients.
Cloud Endpoints
32. Devops: CI & CD (Docker, gitlab, GCP)
Bitbucket
Github
Jenkins
Travis CI
CircleCI
Docker
Gitlab
Cloud Source
Repositories
Stackdriver
Debugger
33. Origin imgae from and modified [DevOps:持續整合&持續交付(Docker、CircleCI、AWS)](http://blog.amowu.com/2015/04/devops-continuous-integration-delivery-
docker-circleci-aws-beanstalk.html)
34. 簡單腳本
◉ Local Development / Test
◉ Gitlab-ci-multi-runner
◉ Local runner exec test - docker
◉ Gitlab runner test docker
◉ gcloud deploy
◉ Google App Engine
◉ Google Cloud Source Repositories
◉ Stackdriver Debugger
37. Register Gitlab runner
$ gitlab-ci-multi-runner register
WARNING: Running in user-mode.
WARNING: The user-mode requires you to manually start builds processing:
WARNING: $ gitlab-runner run
WARNING: Use sudo for system-mode:
WARNING: $ sudo gitlab-runner...
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci):
https://gitlab.com/ci
Please enter the gitlab-ci token for this runner:
<your-gitlab-project-runner-register-token>
Please enter the gitlab-ci description for this runner:
[Kai-Chus-MBP]: edm
Please enter the gitlab-ci tags for this runner (comma separated):
gae,python,edm
Registering runner... succeeded runner=kvwzB1cE
Please enter the executor: ssh, shell, parallels, docker, docker-ssh, virtualbox:
docker
Please enter the default Docker image (eg. ruby:2.1):
cage1016/gitlab-ci-gcp:v1.6
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
38. .gitlab-ci.yaml
image: cage1016/gitlab-ci-gcp:v1.6
before_script:
- export CLOUDSDK_CORE_DISABLE_PROMPTS=1
- export CLOUDSDK_PYTHON_SITEPACKAGES=1
- export GCP_PROJECT=cage-20160705-edm
- export GCP_PROJECT_VERSION=uat
types:
- test
- deploy
test:
stage: test
script:
- sh ./scripts/tests.sh
deploy:
stage: deploy
script:
- sh ./scripts/deploy.sh
only:
- develop
39. .gitlab-ci.yaml (./scripts/tests.sh)
#!/usr/bin/env bash
virtualenv env
source env/bin/activate
# install Google App engine test env packages from requirements.testing.txt
pip install -r requirements.testing.txt
echo $GCLOUD_SERVICE_JSON_KEY > tasks/cage-20160705-edm-cc07ec5bf115.json
# run tests
py.test tasks/tests
41. Local runner exec test docker
// [install gitlab-ci-multi-runner](https://goo.gl/a99Aa4)
// list and register gitlab-ci-runner
$ gitlab-ci-multi-runner list
Listing configured runners ConfigFile=/Users/cage/.gitlab-runner/config.toml
edm Executor=docker Token=<your-token> URL=https://gitlab.com/ci
// prepare a docker-machine for gitlab-ci-multi-runner
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
runner - virtualbox Running tcp://192.168.99.100:2376 v1.11.0
// run a gitlab-ci-multi-runner test via docker
$ gitlab-ci-multi-runner --debug exec docker test --env "GCLOUD_KEY=$GCLOUD_KEY" --env " GCLOUD_ACCOUNT=
$GCLOUD_ACCOUNT" --env="GCP_PROJECT_VERSION=$GCP_PROJECT_VERSION"
42. $ git remote add google https://source.developers.google.com/p/[PROJECT_ID]/r/default
// generates a file named source-context.json, which contains information about the version of the source
code used to build the application
$ gcloud preview app gen-repo-info-file
// push code to google cloud source repositories
$ git push google master Google Cloud Source Repositories - List
49. “5G Google cloud storage for App
engine for FREE
<project-id>.appspot.com
staging.<project-id>.appspot.com
50. “App Engine Admin API
Cloud Source Repositories API
Google Cloud Storage
51. 學習資源
◉ [Best Practices in Email Deliverability - Act-On Software](https:
//www.act-on.com/ebook/email-marketing-deliverability-ebook/)
◉ [Getting Started - SendGrid Documentation | SendGrid](https:
//sendgrid.com/docs/index.html)
◉ [Newsletters spam test by mail-tester.com](http://www.mail-
tester.com/)
◉ [Your Email Reputation](http://www.slideshare.
net/emaildelivered/email-reputation-2)
52. 學習資源
◉ Deploying to App Engine or Managed VMs from Travis CI
◉ [Deploying to App Engine or Managed VMs from Travis CI -
YouTube](https://www.youtube.com/watch?
v=7U4jjRw_AJk&feature=youtu.be)
◉ [GoogleCloudPlatform/continuous-deployment-demo](https:
//github.com/GoogleCloudPlatform/continuous-deployment-
demo)
53. 學習資源
◉ GCP
◉ [Cloud Source Repositories - Private Git Repositories —
Google Cloud Platform](https://cloud.google.com/source-
repositories/)
◉ [Stackdriver Debugger - Production Debugging - Google Cloud
Platform — Google Cloud Platform](https://cloud.google.
com/debugger/)
◉ [Managed VMs lab · kaichu.io](http://kaichu.
io/2015/09/managed-vms-lab/)
54. DevOps (Development & Operations)
Install the necessary apps with
one-click on demand and the
system will automatically finish
the set-up process
Quickly build a development
environment ideally suited for
collaboration
One NAS with Multiple projects
Recommended apps for quick installation : Private Registry, GitLab, and Jenkins.