2020-11-20 06:11:00 +01:00
|
|
|
name: Build & Deploy Production Containers
|
2020-11-18 00:42:44 +01:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
2020-12-04 00:51:37 +01:00
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
- main
|
2020-11-18 00:42:44 +01:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
build:
|
2020-11-20 06:11:00 +01:00
|
|
|
name: Build & Deploy Production Docker image
|
2021-06-17 00:22:23 +02:00
|
|
|
if: github.repository == 'PostHog/posthog'
|
2020-11-18 00:42:44 +01:00
|
|
|
runs-on: ubuntu-20.04
|
|
|
|
steps:
|
|
|
|
- name: Configure AWS credentials
|
|
|
|
uses: aws-actions/configure-aws-credentials@v1
|
|
|
|
with:
|
|
|
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
|
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
|
|
aws-region: us-east-1
|
|
|
|
|
|
|
|
- name: Login to Amazon ECR
|
|
|
|
id: login-ecr
|
|
|
|
uses: aws-actions/amazon-ecr-login@v1
|
|
|
|
|
2021-02-24 23:20:05 +01:00
|
|
|
- name: Fetch posthog-cloud
|
2020-11-18 00:42:44 +01:00
|
|
|
run: |
|
2021-02-24 23:20:05 +01:00
|
|
|
curl -L https://github.com/posthog/posthog-cloud/tarball/master | tar --strip-components=1 -xz --
|
2020-11-18 00:42:44 +01:00
|
|
|
mkdir deploy/
|
|
|
|
|
|
|
|
- name: Checkout master
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
with:
|
2020-12-04 00:51:37 +01:00
|
|
|
# ref defaults to whatever branch the action is operating on. Leaving it blank on master or main will make it
|
|
|
|
# easier to switch if we decide to. Also makes branch deploys easier.
|
|
|
|
# ref: 'master'
|
2020-11-18 00:42:44 +01:00
|
|
|
path: 'deploy/'
|
|
|
|
|
|
|
|
- name: Build, tag, and push image to Amazon ECR
|
2020-11-20 06:11:00 +01:00
|
|
|
id: build-image
|
2020-11-18 00:42:44 +01:00
|
|
|
env:
|
|
|
|
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
|
|
|
|
ECR_REPOSITORY: posthog-production
|
|
|
|
IMAGE_TAG: ${{ github.sha }}
|
|
|
|
run: |
|
|
|
|
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f prod.web.Dockerfile .
|
|
|
|
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
2020-11-20 06:11:00 +01:00
|
|
|
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
|
|
|
|
|
|
|
|
- name: Fill in the new image ID in the Amazon ECS task definition
|
2020-12-04 00:51:37 +01:00
|
|
|
id: task-def-web
|
2020-11-20 06:11:00 +01:00
|
|
|
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
|
|
with:
|
2020-12-04 00:51:37 +01:00
|
|
|
task-definition: deploy/task-definition.web.json
|
2020-11-20 06:11:00 +01:00
|
|
|
container-name: posthog-production
|
|
|
|
image: ${{ steps.build-image.outputs.image }}
|
|
|
|
|
2020-12-04 00:51:37 +01:00
|
|
|
- name: Fill in the new worker image ID in the Amazon ECS task definition
|
|
|
|
id: task-def-worker
|
|
|
|
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
|
|
with:
|
|
|
|
task-definition: deploy/task-definition.worker.json
|
|
|
|
container-name: posthog-production-worker
|
|
|
|
image: ${{ steps.build-image.outputs.image }}
|
|
|
|
|
2021-03-01 13:43:43 +01:00
|
|
|
- name: Fill in the new plugins image ID in the Amazon ECS task definition
|
|
|
|
id: task-def-plugins
|
|
|
|
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
|
|
with:
|
|
|
|
task-definition: deploy/task-definition.plugins.json
|
|
|
|
container-name: posthog-production-plugins
|
|
|
|
image: ${{ steps.build-image.outputs.image }}
|
|
|
|
|
2020-12-04 00:51:37 +01:00
|
|
|
- name: Fill in the new migration image ID in the Amazon ECS task definition
|
|
|
|
id: task-def-migrate
|
|
|
|
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
|
|
with:
|
|
|
|
task-definition: deploy/task-definition.migration.json
|
|
|
|
container-name: posthog-production-migration
|
|
|
|
image: ${{ steps.build-image.outputs.image }}
|
|
|
|
|
|
|
|
- name: Perform migrations
|
|
|
|
run: |
|
|
|
|
aws ecs register-task-definition --cli-input-json file://$TASK_DEFINITION
|
|
|
|
aws ecs run-task --cluster posthog-production-cluster --count 1 --launch-type FARGATE --task-definition posthog-production-migration --network-configuration '{
|
|
|
|
"awsvpcConfiguration": {
|
|
|
|
"subnets": ["subnet-8738fde1"],
|
|
|
|
"securityGroups": ["sg-05a5f7e510b15473c"],
|
2020-12-08 02:45:20 +01:00
|
|
|
"assignPublicIp": "ENABLED"
|
2020-12-04 00:51:37 +01:00
|
|
|
}}'
|
|
|
|
env:
|
|
|
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
|
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
|
|
AWS_DEFAULT_REGION: 'us-east-1'
|
|
|
|
TASK_DEFINITION: ${{ steps.task-def-migrate.outputs.task-definition }}
|
|
|
|
|
|
|
|
- name: Deploy Amazon ECS web task definition
|
2020-11-20 06:11:00 +01:00
|
|
|
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
|
|
|
with:
|
2020-12-04 00:51:37 +01:00
|
|
|
task-definition: ${{ steps.task-def-web.outputs.task-definition }}
|
2020-11-20 06:11:00 +01:00
|
|
|
service: posthog-production
|
|
|
|
cluster: posthog-production-cluster
|
2020-12-04 00:51:37 +01:00
|
|
|
|
|
|
|
- name: Deploy Amazon ECS events task definition
|
|
|
|
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
|
|
|
with:
|
|
|
|
task-definition: ${{ steps.task-def-web.outputs.task-definition }}
|
|
|
|
service: posthog-production-event
|
|
|
|
cluster: posthog-production-cluster
|
|
|
|
|
|
|
|
- name: Deploy Amazon ECS worker task definition
|
|
|
|
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
|
|
|
with:
|
|
|
|
task-definition: ${{ steps.task-def-worker.outputs.task-definition }}
|
|
|
|
service: posthog-production-worker
|
|
|
|
cluster: posthog-production-cluster
|
2020-12-16 03:10:00 +01:00
|
|
|
|
|
|
|
- name: Deploy Amazon ECS plugins task definition
|
|
|
|
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
|
|
|
with:
|
2021-03-01 13:43:43 +01:00
|
|
|
task-definition: ${{ steps.task-def-plugins.outputs.task-definition }}
|
2020-12-16 03:10:00 +01:00
|
|
|
service: posthog-production-plugins
|
|
|
|
cluster: posthog-production-cluster
|
2021-04-19 12:02:11 +02:00
|
|
|
sentry:
|
|
|
|
name: Notify Sentry of a production release
|
|
|
|
runs-on: ubuntu-20.04
|
|
|
|
steps:
|
|
|
|
- name: Checkout master
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Notify Sentry
|
2021-06-17 00:22:23 +02:00
|
|
|
if: github.repository == 'PostHog/posthog'
|
2021-04-19 12:02:11 +02:00
|
|
|
uses: getsentry/action-release@v1
|
|
|
|
env:
|
|
|
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
|
|
|
SENTRY_ORG: posthog
|
|
|
|
SENTRY_PROJECT: posthog
|
|
|
|
with:
|
|
|
|
environment: production
|