written by Nicolas Untz on 2017-04-01

Travis CI can automatically deploy your Lektor content if it has access to your repository; this is well documented here. You simply need to update the .travis.yml file to include a deploy statement directing Travis to run the lektor script:

deploy:
  provider: script
  script: "lektor deploy"

For this web site, we publish to AWS S3 using lektor-s3 and need to provide the credentials to Travis as environment variables (go to More options, settings to define them in Travis).

Note: we use specific AWS IAM credentials and policies to limit what Travis can do. First:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1491117107000",
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "arn:aws:s3:::nuntz.com"
            ]
        },
        {
            "Sid": "Stmt1491117177000",
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "arn:aws:s3:::nuntz.com/*"
            ]
        },
        {
            "Sid": "Stmt1491117192000",
            "Effect": "Allow",
            "Action": [
                "s3:ListAllMyBuckets"
            ],
            "Resource": [
                "arn:aws:s3:::*"
            ]
        }
    ]
}

Second, because we use the CloudFront invalidation feature of lektor-s3:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1491117901000",
            "Effect": "Allow",
            "Action": [
                "cloudfront:CreateInvalidation"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

For reference, here is the full travis.yml file for this web site:

language: python
python: 2.7
cache:
  directories:
    - $HOME/.cache/pip
    - $HOME/.cache/lektor/builds
install: "pip install Lektor"
script: "lektor build"
deploy:
  provider: script
  script: "lektor deploy"