Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.
Merged
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
14 changes: 7 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
with:
mask-password: "false"

- name: Build, tag, and push docker image to Amazon ECR
- name: Build, tag, and push cube api docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: sync-svc-cube
REPOSITORY: prod-sync-cube-ecr
IMAGE_TAG: "${{ github.sha }}"
run: |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f docker/cube/Dockerfile .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG

- name: Update cube-api Task Definition with latest image
Expand All @@ -41,28 +41,28 @@ jobs:
with:
task-definition-family: cube_api
container-name: cube-api
image: ${{ steps.login-ecr.outputs.registry }}/sync-svc-cube:${{ github.sha }}
image: ${{ steps.login-ecr.outputs.registry }}/prod-sync-cube-ecr:${{ github.sha }}

- name: Update cube-refresh-worker Task Definition with latest image
id: cube-refresh-worker-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1.6.2
with:
task-definition-family: cube_refresh_worker
container-name: cube-refresh-worker
image: ${{ steps.login-ecr.outputs.registry }}/sync-svc-cube:${{ github.sha }}
image: ${{ steps.login-ecr.outputs.registry }}/prod-sync-cube-ecr:${{ github.sha }}

- name: Deploy cube-api task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2.3.0
with:
task-definition: ${{ steps.cube-api-task-def.outputs.task-definition }}
service: cube_api
cluster: production
cluster: prod-sync_cluster

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixing - and _ 😢

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep yep! i noticed it as well. I will fix in a follow up!

wait-for-service-stability: true

- name: Deploy cube-refresh-worker task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2.3.0
with:
task-definition: ${{ steps.cube-refresh-worker-task-def.outputs.task-definition }}
service: cube_refresh_worker
cluster: production
cluster: prod-sync_cluster
wait-for-service-stability: true
6 changes: 0 additions & 6 deletions Dockerfile

This file was deleted.

17 changes: 17 additions & 0 deletions deploy_cubestore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

AWS_REGION="us-east-1"
ECR_REPOSITORY="prod-sync-cubestore-ecr"
Copy link

@shughes-uk shughes-uk Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just store the full ECR repo in a SSM parameter and pull that? Would be less fragile.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya let me do this in a follow up - I need to do multiple envs for this as well


AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text)
REGISTRY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
IMAGE_TAG=$(git rev-parse --short HEAD 2>/dev/null || date +%s)

aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $REGISTRY

docker build --platform linux/amd64 -t $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f docker/cubestore/Dockerfile .
Copy link

@shughes-uk shughes-uk Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe add linux/arm64 as a second platform target. The rationale is

  • Local dev is almost always going to be arm64, we want to ensure we still work for devs
  • Graviton (aws ARM) is great and we will probably want to use that ASAP honestly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed so local dev is going to use docker-compose so ill update in my next pr for that - I also need to test the ARM cube image to see if it works!

docker push $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

echo "New cubestore image pushed to ECR: $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG. Please update terraform cubestore services task definitions accordingly."
11 changes: 11 additions & 0 deletions docker/cube/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM cubejs/cube:v1.1.9

RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY cube.js cube.js
COPY fetch.js fetch.js
RUN mkdir model
COPY model/ model/
3 changes: 3 additions & 0 deletions docker/cubestore/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM cubejs/cubestore:latest

RUN apt-get update && apt-get install -y curl
19 changes: 19 additions & 0 deletions terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 0 additions & 33 deletions terraform/ecr.tf

This file was deleted.

117 changes: 117 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,120 @@ provider "aws" {
}
}
}

module "vpc" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems sensible we will probably want to use the same VPC for sync_backend/tasks

source = "terraform-aws-modules/vpc/aws"
version = ">=5.7.1"

name = "production-vpc"
cidr = "10.0.0.0/16"

azs = ["us-east-1a", "us-east-1b", "us-east-1d", "us-east-1c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24", "10.0.4.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24", "10.0.104.0/24"]
enable_dns_hostnames = true
enable_dns_support = true
enable_nat_gateway = true
create_igw = true
}

module "production_cube_cluster" {
source = "./modules/cube-cluster"

cluster_prefix = "prod-sync"
vpc = module.vpc
cube_api_domain_name = "cube-api.synccomputing.com"
cube_shared_env = [
{
name = "CUBEJS_DB_SSL"
value = "true"
},
{
name = "CUBEJS_DB_TYPE"
value = "postgres"
},
{
name = "CUBEJS_DB_HOST"
value = "ec2-3-221-59-105.compute-1.amazonaws.com"
},
{
name = "CUBEJS_DB_PORT"
value = "5432"
},
{
name = "CUBEJS_DB_USER"
value = "cube"
},
{
name = "CUBEJS_DB_NAME"
value = "d20nhfliefb6aa"
},
{
name = "CUBEJS_SCHEMA_PATH"
value = "model"
},
{
name = "CUBEJS_DEV_MODE"
value = "false"
},
{
name = "NODE_ENV",
value = "production"
},
{
name = "CUBEJS_JWK_URL"
value = "https://sync-prod.us.auth0.com/.well-known/jwks.json"
},
{
name = "CUBEJS_JWT_AUDIENCE"
value = "https://api.synccomputing.com"
},
{
name = "CUBEJS_JWT_ISSUER"
value = "https://login.app.synccomputing.com/"
},
{
name = "CUBEJS_JWT_ALGS"
value = "RS256"
},
{
name = "CUBEJS_JWT_CLAIMS_NAMESPACE"
value = "https://synccomputing.com/"
}
]
cube_shared_secrets = [
{ name = "CUBEJS_DB_PASS", valueFrom = aws_secretsmanager_secret.postgres_cube_user_pw.arn },
{ name = "CUBEJS_JWT_KEY", valueFrom = aws_secretsmanager_secret.auth0_jwt_key.arn },
]
}

resource "aws_secretsmanager_secret" "postgres_cube_user_pw" {
name = "production/postgres-cube-user-pw"
}

resource "aws_secretsmanager_secret" "auth0_jwt_key" {
name = "production/auth0-jwt-key"
}

resource "aws_iam_openid_connect_provider" "github_openid" {
url = "https://token.actions.githubusercontent.com"

client_id_list = [
"sts.amazonaws.com",
]

thumbprint_list = ["cf23df2207d99a74fbe169e3eba035e633b65d94"]
}

module "iam_github_oidc_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-github-oidc-role"
name = "github_actions_role"
path = "/system/"
description = "GitHub IAM role for GitHub actions"

subjects = ["synccomputingcode/sync-svc-cube-v2:*"]

policies = {
GitHubActionsPolicy = module.production_cube_cluster.cube_repo_ecr_policy.arn
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ data "aws_cloudfront_origin_request_policy" "all_viewers" {
name = "Managed-AllViewer"
}

resource "aws_cloudfront_distribution" "sync_svc_cube_cdn" {
aliases = [local.domain_name, "www.${local.domain_name}"]
resource "aws_cloudfront_distribution" "cube_cdn" {
aliases = [var.cube_api_domain_name]
comment = "Cloudfront distribution for cube.dev api"
price_class = "PriceClass_100"
is_ipv6_enabled = true
Expand All @@ -25,12 +25,6 @@ resource "aws_cloudfront_distribution" "sync_svc_cube_cdn" {
domain_name = local.api_domain_name
origin_id = local.api_domain_name

# vpc_origin_config {
# vpc_origin_id = aws_cloudfront_vpc_origin.alb.id
# origin_keepalive_timeout = 5
# origin_read_timeout = 30
# }

custom_origin_config {
http_port = 80
https_port = 443
Expand Down Expand Up @@ -64,4 +58,4 @@ resource "aws_cloudfront_distribution" "sync_svc_cube_cdn" {
locations = []
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "aws_cloudwatch_log_group" "main" {
name = "/ecs/sync-svc-cube/production"
name = "/ecs/${var.cluster_prefix}-cube-logs"
retention_in_days = 14
}
65 changes: 65 additions & 0 deletions terraform/modules/cube-cluster/ecr.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
resource "aws_ecr_repository" "cube_repo" {
name = "${var.cluster_prefix}-cube-ecr"
image_tag_mutability = "IMMUTABLE"

image_scanning_configuration {
scan_on_push = true
}
}

resource "aws_ecr_lifecycle_policy" "cube_lf_policy" {
repository = aws_ecr_repository.cube_repo.name

policy = <<EOF
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"rules": [
{
"rulePriority": 1,
"description": "Keep last 30 images",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["v"],
"countType": "imageCountMoreThan",
"countNumber": 30
},
"action": {
"type": "expire"
}
}
]
}
EOF
}

resource "aws_ecr_repository" "cubestore_repo" {
name = "${var.cluster_prefix}-cubestore-ecr"
image_tag_mutability = "IMMUTABLE"

image_scanning_configuration {
scan_on_push = true
}
}

resource "aws_ecr_lifecycle_policy" "cubestore_lf_policy" {
repository = aws_ecr_repository.cubestore_repo.name

policy = <<EOF
{
"rules": [
{
"rulePriority": 1,
"description": "Keep last 30 images",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["v"],
"countType": "imageCountMoreThan",
"countNumber": 30
},
"action": {
"type": "expire"
}
}
]
}
EOF
}
Loading