-
Notifications
You must be signed in to change notification settings - Fork 0
Time to parameterize #3
Changes from all commits
9b6a302
7d0b1f4
16ffdbe
cf4ba38
5475e70
1bb866c
64f9c6e
30ca098
8311306
714ee22
1ca66c3
b16b89b
ca13f5a
19e48f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| 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" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 . | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would maybe add
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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." | ||
| 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/ |
| 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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,120 @@ provider "aws" { | |
| } | ||
| } | ||
| } | ||
|
|
||
| module "vpc" { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
|---|---|---|
| @@ -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 | ||
| } |
| 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 | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Way prefer this method of defining lifecycle policies btw https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_lifecycle_policy_document |
||
| "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 | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mixing
-and_😢There was a problem hiding this comment.
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!