mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-25 11:17:50 +01:00
e4f40cf1ab
Co-authored-by: xneyder <xneyder@gmail.com>
110 lines
4.2 KiB
YAML
110 lines
4.2 KiB
YAML
# This workflow handles deploying a branch to the pull request cluster, for
|
|
# testing purposes. It is locked down so that it can only be used by people who
|
|
# are a member of the PostHog Github org
|
|
|
|
name: PR - Preview Deploy
|
|
|
|
on:
|
|
workflow_call:
|
|
|
|
jobs:
|
|
deploy_preview:
|
|
name: Deploy preview environment
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
id-token: write
|
|
contents: read
|
|
deployments: write
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Depot CLI
|
|
uses: depot/setup-action@v1
|
|
|
|
- name: Login to DockerHub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USER }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- uses: aws-actions/configure-aws-credentials@v4
|
|
with:
|
|
aws-region: us-east-1
|
|
role-to-assume: arn:aws:iam::169684386827:role/github-terraform-infra-role
|
|
role-duration-seconds: 3600
|
|
|
|
- name: connect to tailscale
|
|
uses: tailscale/github-action@8b804aa882ac3429b804a2a22f9803a2101a0db9
|
|
env:
|
|
TS_EXPERIMENT_OAUTH_AUTHKEY: true
|
|
with:
|
|
version: 1.42.0
|
|
authkey: ${{ secrets.TAILSCALE_OAUTH_SECRET }}
|
|
args: --advertise-tags tag:github-runner
|
|
|
|
- name: Login to Amazon ECR
|
|
id: aws-ecr
|
|
uses: aws-actions/amazon-ecr-login@v2
|
|
|
|
- name: Build and push PR test image
|
|
id: build
|
|
uses: depot/build-push-action@v1
|
|
with:
|
|
context: .
|
|
buildx-fallback: false # the fallback is so slow it's better to just fail
|
|
push: true
|
|
tags: ${{ steps.aws-ecr.outputs.registry }}/pr-test:${{ github.event.pull_request.head.sha }}
|
|
platforms: linux/arm64,linux/amd64
|
|
build-args: COMMIT_HASH=${{ github.event.pull_request.head.sha }}
|
|
|
|
- name: start deployment
|
|
uses: bobheadxi/deployments@v1.4.0
|
|
id: deployment
|
|
with:
|
|
step: start
|
|
env: pr-${{ github.head_ref }}
|
|
ref: ${{ github.head_ref }}
|
|
|
|
- name: Deploy hobby
|
|
id: deploy_hobby
|
|
run: |
|
|
aws eks update-kubeconfig --name "posthog-dev"
|
|
kubectl config set-cluster arn:aws:eks:us-east-1:169684386827:cluster/posthog-dev --server=https://eks-posthog-dev --tls-server-name 8BD6E1D2FEBDE47C8177E29CAC9E6C61.gr7.us-east-1.eks.amazonaws.com
|
|
|
|
export PR_NUM=${{ github.event.number }}
|
|
export BRANCH_NAME=${{ github.head_ref }}
|
|
export BRANCH_NAME_HASH=$(echo -n ${{ github.head_ref }} | md5sum | cut -c 1-8)
|
|
export HOSTNAME=pr-$PR_NUM-${BRANCH_NAME_HASH}
|
|
export HOSTNAME=${HOSTNAME:0:38}
|
|
export HOSTNAME=${HOSTNAME%%-}
|
|
export NAMESPACE="hobby"
|
|
export REGISTRY_URL=${{ steps.aws-ecr.outputs.registry }}/pr-test
|
|
export DOCKER_TAG=${{ github.event.pull_request.head.sha }}
|
|
|
|
envsubst < .github/pr-deploy/hobby.yaml.tmpl > .github/pr-deploy/hobby.yaml
|
|
|
|
#Clean and deploy
|
|
kubectl -n $NAMESPACE delete -f .github/pr-deploy/hobby.yaml || true
|
|
kubectl -n $NAMESPACE apply -f .github/pr-deploy/hobby.yaml
|
|
|
|
echo "url=$HOSTNAME.dev.posthog.dev" >> $GITHUB_OUTPUT
|
|
|
|
- name: update deployment status
|
|
uses: bobheadxi/deployments@v1
|
|
with:
|
|
step: finish
|
|
status: ${{ job.status }}
|
|
env: ${{ steps.deployment.outputs.env }}
|
|
ref: ${{ github.head_ref }}
|
|
env_url: https://${{ steps.deploy_hobby.outputs.url }}
|
|
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
|