2022-03-21 21:44:32 +07:00
|
|
|
name: Deploy Preview to Staging
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
inputs:
|
|
|
|
front_branch:
|
|
|
|
description: Front Branch
|
|
|
|
required: true
|
|
|
|
default: 'main'
|
|
|
|
api_branch:
|
|
|
|
description: API Branch
|
|
|
|
required: true
|
|
|
|
default: 'main'
|
|
|
|
jobs:
|
|
|
|
deploy-front:
|
|
|
|
name: Deploy Front
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Front Repository Dispatch
|
|
|
|
uses: peter-evans/repository-dispatch@v1
|
|
|
|
with:
|
|
|
|
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
|
|
|
repository: getlago/lago-front
|
|
|
|
event-type: deploy-preview
|
|
|
|
client-payload: '{ "branch": "${{ github.event.inputs.front_branch }}" }'
|
2022-03-22 21:01:38 +07:00
|
|
|
build-api-image:
|
|
|
|
name: Build API Image
|
2022-03-21 21:44:32 +07:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2022-03-22 21:01:38 +07:00
|
|
|
- name: Checkout API
|
|
|
|
uses: actions/checkout@v3
|
2022-03-21 21:44:32 +07:00
|
|
|
with:
|
2022-03-22 21:01:38 +07:00
|
|
|
repository: getlago/lago-api
|
|
|
|
ref: ${{ github.event.inputs.api_branch }}
|
|
|
|
path: api
|
2022-03-21 21:44:32 +07:00
|
|
|
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
2022-03-22 21:01:38 +07:00
|
|
|
- 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
|
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v1
|
|
|
|
- name: Cache Docker layers
|
|
|
|
uses: actions/cache@v2
|
|
|
|
with:
|
|
|
|
path: /tmp/.buildx-cache
|
|
|
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
|
|
restore-keys: |
|
|
|
|
${{ runner.os }}-buildx-
|
|
|
|
- name: Docker tag
|
|
|
|
id: docker_tag
|
|
|
|
env:
|
|
|
|
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
|
|
|
|
ECR_REPOSITORY: lago-api-staging
|
|
|
|
IMAGE_TAG: ${{ github.event.inputs.api_branch }}
|
|
|
|
run: echo "##[set-output name=tag;]$(echo $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG)"
|
|
|
|
- name: Build and push
|
|
|
|
uses: docker/build-push-action@v2
|
|
|
|
env:
|
|
|
|
RAILS_ENV: staging
|
|
|
|
with:
|
2022-03-22 21:07:12 +07:00
|
|
|
context: ./api
|
2022-03-22 21:01:38 +07:00
|
|
|
push: true
|
|
|
|
tags: ${{ steps.docker_tag.outputs.tag }}
|
|
|
|
cache-from: type=local,src=/tmp/.buildx-cache
|
|
|
|
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
|
|
|
- name: Move cache
|
|
|
|
run: |
|
|
|
|
rm -rf /tmp/.buildx-cache
|
|
|
|
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
2022-03-22 21:02:37 +07:00
|
|
|
api-deploy:
|
|
|
|
name: Deploy API
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs: [build-api-image]
|
|
|
|
container:
|
|
|
|
image: getlago/deploy-staging
|
|
|
|
env:
|
|
|
|
PORTER_HOST: https://dashboard.getporter.dev
|
|
|
|
PORTER_CLUSTER: ${{ secrets.PORTER_CLUSTER }}
|
|
|
|
PORTER_PROJECT: ${{ secrets.PORTER_PROJECT }}
|
|
|
|
PORTER_TOKEN: ${{ secrets.PORTER_TOKEN_2643 }}
|
|
|
|
steps:
|
|
|
|
- name: Checkout API
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
with:
|
|
|
|
repository: getlago/lago-api
|
|
|
|
ref: ${{ github.event.inputs.api_branch }}
|
|
|
|
path: api
|
|
|
|
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
|
|
|
- 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
|
|
|
|
- name: Replace Variables in values.yaml
|
2022-03-22 21:01:38 +07:00
|
|
|
env:
|
2022-03-22 21:02:37 +07:00
|
|
|
ECR_REPOSITORY: ${{ steps.login-ecr.outputs.registry }}/lago-api-staging
|
|
|
|
BRANCH: ${{ github.event.inputs.api_branch }}
|
|
|
|
DATABASE_URL: postgres://lago:${{ secrets.DB_STAGING_PASSWORD }}@${{ secrets.DB_STAGING_HOST}}:5432/${{ github.event.inputs.api_branch }}
|
2022-03-22 21:12:38 +07:00
|
|
|
run: envsubst < ./api/porter/values.yaml > ./api/porter/env_values.yaml
|
2022-03-22 21:02:37 +07:00
|
|
|
- name: Configure kubectl
|
|
|
|
run: echo "${{ secrets.KUBE_STAGING_CONFIG }}" | base64 -d > kubeconfig.yaml
|
|
|
|
- name: Get Helm deployment
|
|
|
|
id: helm_deployment
|
|
|
|
run: echo "::set-output name=deployment::$(helm --kubeconfig ./kubeconfig.yaml list -f ${{ github.event.inputs.api_branch }}-api -o=json | jq '.[0].name')"
|
|
|
|
- name: Delete Porter app
|
|
|
|
if: ${{ steps.helm_deployment.outputs.deployment != 'null' }}
|
|
|
|
run: |
|
|
|
|
helm --kubeconfig ./kubeconfig.yaml uninstall ${{ github.event.inputs.api_branch }}-api
|
|
|
|
- name: Create Porter app
|
|
|
|
uses: porter-dev/porter-cli-action@v0.1.0
|
|
|
|
with:
|
2022-03-22 21:12:38 +07:00
|
|
|
command: create web --app ${{ github.event.inputs.api_branch }}-api --source registry --values ./api/porter/env_values.yaml --image ${{ steps.login-ecr.outputs.registry }}/lago-api-staging:${{ github.event.inputs.api_branch }}
|
2022-03-22 21:01:38 +07:00
|
|
|
|
2022-03-22 21:02:37 +07:00
|
|
|
|