Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 714ee22

Browse files
committed
Add cubestore script
1 parent 8311306 commit 714ee22

File tree

8 files changed

+80
-9
lines changed

8 files changed

+80
-9
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ jobs:
2626
with:
2727
mask-password: "false"
2828

29-
- name: Build, tag, and push docker image to Amazon ECR
29+
- name: Build, tag, and push cube api docker image to Amazon ECR
3030
env:
3131
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
3232
REPOSITORY: prod-sync-cube-ecr
3333
IMAGE_TAG: "${{ github.sha }}"
3434
run: |
35-
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
35+
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f docker/cube/Dockerfile .
3636
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
3737
3838
- name: Update cube-api Task Definition with latest image

deploy_cubestore.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
AWS_REGION="us-east-1"
6+
ECR_REPOSITORY="prod-sync-cubestore-ecr"
7+
8+
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text)
9+
REGISTRY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
10+
IMAGE_TAG=$(git rev-parse --short HEAD 2>/dev/null || date +%s)
11+
12+
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $REGISTRY
13+
14+
docker build --platform linux/amd64 -t $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f docker/cubestore/Dockerfile .
15+
docker push $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
16+
17+
echo "New cubestore image pushed to ECR: $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG. Please update terraform cubestore services task definitions accordingly."
File renamed without changes.

docker/cubestore/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM cubejs/cubestore:latest
2+
3+
RUN apt-get update && apt-get install -y curl

terraform/modules/cube-cluster/ecr.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,37 @@ resource "aws_ecr_lifecycle_policy" "cube_lf_policy" {
2929
]
3030
}
3131
EOF
32+
}
33+
34+
resource "aws_ecr_repository" "cubestore_repo" {
35+
name = "${var.cluster_prefix}-cubestore-ecr"
36+
image_tag_mutability = "IMMUTABLE"
37+
38+
image_scanning_configuration {
39+
scan_on_push = true
40+
}
41+
}
42+
43+
resource "aws_ecr_lifecycle_policy" "cubestore_lf_policy" {
44+
repository = aws_ecr_repository.cubestore_repo.name
45+
46+
policy = <<EOF
47+
{
48+
"rules": [
49+
{
50+
"rulePriority": 1,
51+
"description": "Keep last 30 images",
52+
"selection": {
53+
"tagStatus": "tagged",
54+
"tagPrefixList": ["v"],
55+
"countType": "imageCountMoreThan",
56+
"countNumber": 30
57+
},
58+
"action": {
59+
"type": "expire"
60+
}
61+
}
62+
]
63+
}
64+
EOF
3265
}

terraform/modules/cube-cluster/ecs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ resource "aws_ecs_task_definition" "cubestore_router" {
380380
container_definitions = jsonencode([
381381
{
382382
name = "cubestore-router"
383-
image = "${var.cubestore_image}"
383+
image = "${aws_ecr_repository.cubestore_repo.repository_url}:8311306"
384384
cpu = tonumber(var.cubestore_router_resources.cpu)
385385
memory = tonumber(var.cubestore_router_resources.memory)
386386
essential = true
@@ -502,7 +502,7 @@ resource "aws_ecs_task_definition" "cubestore" {
502502
container_definitions = jsonencode([
503503
{
504504
name = "cubestore"
505-
image = "${var.cubestore_image}"
505+
image = "${aws_ecr_repository.cubestore_repo.repository_url}:8311306"
506506
cpu = tonumber(var.cubestore_worker_resources.cpu)
507507
memory = tonumber(var.cubestore_worker_resources.memory)
508508
essential = true

terraform/modules/cube-cluster/iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ resource "aws_iam_policy" "cube_repo_ecr_policy" {
2727
"ecr:PutImage",
2828
"ecr:UploadLayerPart"
2929
],
30-
"Resource" : aws_ecr_repository.cube_repo.arn
30+
"Resource" : [aws_ecr_repository.cube_repo.arn, aws_ecr_repository.cubestore_repo.arn]
3131
},
3232
{
3333
"Sid" : "AllowEcsServiceDeploys",

terraform/modules/cube-cluster/variables.tf

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,43 @@ variable "vpc" {
77
type = any
88
}
99

10+
data "aws_vpc" "selected" {
11+
id = var.vpc.vpc_id
12+
}
13+
14+
data "aws_nat_gateways" "selected" {
15+
filter {
16+
name = "vpc-id"
17+
values = [var.vpc.vpc_id]
18+
}
19+
}
20+
21+
data "aws_internet_gateway" "selected" {
22+
filter {
23+
name = "attachment.vpc-id"
24+
values = [var.vpc.vpc_id]
25+
}
26+
}
27+
1028
resource "null_resource" "validate_vpc" {
1129
lifecycle {
1230
precondition {
13-
condition = var.vpc.enable_dns_support
31+
condition = data.aws_vpc.selected.enable_dns_support
1432
error_message = "The VPC must have enable_dns_support = true"
1533
}
1634

1735
precondition {
18-
condition = var.vpc.enable_dns_hostnames
36+
condition = data.aws_vpc.selected.enable_dns_hostnames
1937
error_message = "The VPC must have enable_dns_hostnames = true"
2038
}
2139

2240
precondition {
23-
condition = var.vpc.enable_nat_gateway
41+
condition = length(data.aws_nat_gateways.selected.ids) > 0
2442
error_message = "The VPC must have at least one NAT Gateway"
2543
}
2644

2745
precondition {
28-
condition = var.vpc.create_igw
46+
condition = can(data.aws_internet_gateway.selected.id)
2947
error_message = "The VPC must have an Internet Gateway"
3048
}
3149
}

0 commit comments

Comments
 (0)