Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 9 additions & 40 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,60 +91,29 @@ jobs:
- name: Build App
run: make ${{ (env.DEPLOY_PROD == 'true' && 'prod') || 'stage' }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
if: ${{ env.DEPLOY_PROD == 'true' || env.DEPLOY_STAGE == 'true' }}
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
if: ${{ env.DEPLOY_PROD == 'true' || env.DEPLOY_STAGE == 'true' }}
uses: aws-actions/amazon-ecr-login@v1

- name: Make build context
if: ${{ env.DEPLOY_PROD == 'true' || env.DEPLOY_STAGE == 'true' }}
run: |
docker context create builders

- name: Setup buildx
uses: docker/setup-buildx-action@v2
if: ${{ env.DEPLOY_PROD == 'true' || env.DEPLOY_STAGE == 'true' }}
with:
install: true
endpoint: builders

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build docker image
uses: docker/build-push-action@v3
if: ${{ env.DEPLOY_PROD == 'true' || env.DEPLOY_STAGE == 'true' }}
with:
context: .
file: docker/partial.Dockerfile
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ (env.DEPLOY_PROD == 'true' && '7tv') || '7tv-stage' }}/website:latest
${{ steps.login-ecr.outputs.registry }}/${{ (env.DEPLOY_PROD == 'true' && '7tv') || '7tv-stage' }}/website:${{ github.sha }}
ghcr.io/seventv/website:latest
ghcr.io/seventv/website:${{ github.sha }}
push: true

- name: Update deployment template
uses: danielr1996/envsubst-action@1.1.0
if: ${{ env.DEPLOY_PROD == 'true' || env.DEPLOY_STAGE == 'true' }}
env:
IMAGE: ${{ steps.login-ecr.outputs.registry }}/${{ (env.DEPLOY_PROD == 'true' && '7tv') || '7tv-stage' }}/website:${{ github.sha }}
with:
input: k8s/${{ (env.DEPLOY_PROD == 'true' && 'production') || 'staging' }}.template.yaml
output: k8s/deploy.yaml

- name: Setup Kubectl
uses: azure/setup-kubectl@v3.2

- name: Deploy to k8s
if: ${{ env.DEPLOY_PROD == 'true' || env.DEPLOY_STAGE == 'true' }}
env:
KUBE_CONFIG_DATA: ${{ (env.DEPLOY_PROD == 'true' && secrets.KUBECONFIG) || secrets.KUBECONFIG_STAGE }}
run: |
mkdir -p ~/.kube
(echo $KUBE_CONFIG_DATA | base64 -d) >> ~/.kube/config

kubectl apply -f k8s/deploy.yaml
1 change: 0 additions & 1 deletion k8s/.gitignore

This file was deleted.

103 changes: 0 additions & 103 deletions k8s/production.template.yaml

This file was deleted.

103 changes: 0 additions & 103 deletions k8s/staging.template.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.terraform.lock.hcl
.terraform
22 changes: 22 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
terraform {
backend "remote" {
hostname = "app.terraform.io"
organization = "7tv"

workspaces {
prefix = "7tv-website-"
}
}
}

locals {
workspace = trimprefix(terraform.workspace, "7tv-website-")
}

module "eventapi" {
source = "./website"
docker_image = var.eventapi_docker_image
max_replicas = local.workspace == "prod" ? 10 : 1
min_replicas = local.workspace == "prod" ? 5 : 1
seventv_domain = var.seventv_domain
}
18 changes: 18 additions & 0 deletions terraform/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.18.1"
}
}
}

locals {
kubeconfig = yamldecode(base64decode(data.terraform_remote_state.infra.outputs.kubeconfig))
}

provider "kubernetes" {
host = local.kubeconfig.clusters[0].cluster.server
cluster_ca_certificate = base64decode(local.kubeconfig.clusters[0].cluster.certificate-authority-data)
token = local.kubeconfig.users[0].user.token
}
19 changes: 19 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "eventapi_docker_image" {
type = string
default = "ghcr.io/seventv/website:latest"
}

data "terraform_remote_state" "infra" {
backend = "remote"

config = {
organization = "7tv"
workspaces = {
name = "7tv-infra-${trimprefix(terraform.workspace, "7tv-website-")}"
}
}
}

variable "seventv_domain" {
type = string
}
Loading