Creating Wishlist2Text website – Part 4 Deployment

Hello, the is the final post from a series how I build https://wishlist2text.appspot.com
I will describe how I deploy a website in google app engine using Travis CI. You can read the previous post here, here, and here.

To start I need Travis CI account. For open source repositories, an account is free, you just need to log in with GitHub credentials. Also, you need to publish the code on the GitHub server.
After the code is published open Travis settings and enable the repository.

Also, I need the google console account. The account can be created here, create an account is for free but will require to add a credit card and charge 1 dollar for verification. Here is nice documentation from google how to enable app engine deployment.

As the next step, I need to create a .travis.yml file which describes all build steps.

dist: xenial
language: python
env:
  global:
    - API_KEY=$steam_api
addons:
  snaps:
    - yq
python:
- '3.7'
before_install:
- openssl aes-256-cbc -K $encrypted_89b14f2b782e_key -iv $encrypted_89b14f2b782e_iv
  -in wishlist2text-5d2f14ad267b.json.enc -out wishlist2text-5d2f14ad267b.json -d
install:
- pip install -r requirements-dev.txt
- yq w -i app.yaml env_variables.API_KEY $steam_api
- yq w -i app.yaml env_variables.SECRET_KEY $secret_key
script:
- flake8 .
- pytest --cov .
after_success:
- coveralls
deploy:
  provider: gae
  keyfile: wishlist2text-5d2f14ad267b.json
  project: wishlist2text
  skip_cleanup: true

Lines from dist to python – this is a general configuration where I specified which version of OS to use and python version. In before_install I am decrypting my app engine key which I am storing in a repository encrypted. 
In the install section, I am installing packages from requirements-dev.txt where I am storing my website dev dependency. Here is the content of my requirements-dev.txt

requests
flask
flask-wtf
flask-restful
flake8
pytest
pytest-cov
coveralls

Then I am replacing my steam_api and secret key using yq tool in app engine config. And here is my app engine config.

runtime: python37
handlers:
- url: /.*
  script: auto

After yq command executed a new section env_variables will be created and API_KEY and SECRET_KEY will be added. This variable will set an env variable automatically by google app engine.

Once all configuration is completed I run tests, flake8 will do lint check and pytest will run unit tests which are not created yet. After tests finish coveralls upload unit test result on https://coveralls.io

If tests finish successfully deployment will begin. In the deployment section, I am specifying a provider which I am using. More providers can be found here.  Travis automatically triggers build on every commit and PR. Also, a job can be started manually.

Trigger build and wait while it running. Open google app engine and you should see

Open url provided by Google in the browser and test app