Skip to content

Instantly share code, notes, and snippets.

@dl6nm
Last active May 14, 2020 13:05
Show Gist options
  • Save dl6nm/b02406ed0931fcf411e7a162ee29ea81 to your computer and use it in GitHub Desktop.
Save dl6nm/b02406ed0931fcf411e7a162ee29ea81 to your computer and use it in GitHub Desktop.
Configuration templates for Google App Engine Python 3 standard environment with CI/CD .gitlab-ci.yml
# https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore
#
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore
# Python pycache:
__pycache__/
# Ignored by the build system
/setup.cfg
# IDE and project specific ignore list
.idea/
docs/
instance/
*egg*/
.pytest_cache/
Pipfile*
image: google/cloud-sdk:alpine
before_script:
- apk add gettext
- export APP_VERSION_DOTTED=`git describe`
- export APP_VERSION=`echo $APP_VERSION_DOTTED | sed -r 's/\./\-/g'`
- echo __version__=\'$APP_VERSION_DOTTED\' > papa/version.py
- echo $SERVICE_ACCOUNT > /tmp/$CI_PIPELINE_ID.json
- envsubst < app.yaml.template > app.yaml
- gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
deploy_dev:
stage: deploy
environment:
name: development
url: https://myservice-dev.example.com
only:
- develop
script:
- gcloud --quiet --project $PROJECT_ID app deploy --version $APP_VERSION
deploy_prod:
stage: deploy
environment:
name: production
url: https://myservice.example.com
only:
- master
script:
- gcloud --quiet --project $PROJECT_ID app deploy --no-promote --version $APP_VERSION
# when: manual
after_script:
- rm /tmp/$CI_PIPELINE_ID.json
service: default
runtime: python37
automatic_scaling:
min_instances: 0
# max_instances: 10
env_variables:
SECRET_KEY: "MySuperSecretKey"
APP_ENV: "development"
handlers:
# - url: /images
# static_dir: static/images
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
service: default
runtime: python37
automatic_scaling:
min_instances: 0
# max_instances: 10
env_variables:
SECRET_KEY: "${SECRET_KEY}"
APP_ENV: "${APP_ENV}"
handlers:
# - url: /images
# static_dir: static/images
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
# https://cloud.google.com/appengine/docs/standard/python3/scheduling-jobs-with-cron-yaml
# > gcloud app deploy dispatch.yaml
# https://cloud.google.com/appengine/docs/standard/python3/reference/dispatch-yaml
dispatch:
# Send all myservice specific traffic to the my-service
- url: "myservice.example.com/*"
service: my-service
""" Get the current application version from git describe """
import subprocess
def get_version():
return subprocess.check_output(['git', 'describe']).strip().decode('utf-8')
__version__ = get_version()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment