From 89c10fffde680d9eec35b01d5b61aa0c904331f4 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Sat, 25 Apr 2020 23:39:27 -0400 Subject: [PATCH] Integrated cluster into stack Update pipes Update actions/checkout Fix s3 url --- .github/workflows/push_develop.yml | 4 +++- .github/workflows/push_production.yml | 13 +++++++++++-- .gitmodules | 3 +++ cloudformation/cluster | 1 + cloudformation/nakama/top.yaml | 28 +++++++++++++++++++++------ 5 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 .gitmodules create mode 160000 cloudformation/cluster diff --git a/.github/workflows/push_develop.yml b/.github/workflows/push_develop.yml index 319e8ed..d076095 100644 --- a/.github/workflows/push_develop.yml +++ b/.github/workflows/push_develop.yml @@ -11,7 +11,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Repo - uses: actions/checkout@v1 + uses: actions/checkout@v2.1.0 + with: + submodules: 'true' - name: Ship to S3 uses: jakejarvis/s3-sync-action@master with: diff --git a/.github/workflows/push_production.yml b/.github/workflows/push_production.yml index 826b5b4..72020ee 100644 --- a/.github/workflows/push_production.yml +++ b/.github/workflows/push_production.yml @@ -11,7 +11,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Repo - uses: actions/checkout@v1 + uses: actions/checkout@v2.1.0 + with: + submodules: 'true' - name: Ship to S3 uses: jakejarvis/s3-sync-action@master with: @@ -22,4 +24,11 @@ jobs: DEST_DIR: nakama/production/cloudformation AWS_S3_BUCKET: sumu-stacks AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} \ No newline at end of file + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + - name: Deploy to AWS CloudFormation + uses: aws-actions/aws-cloudformation-github-deploy@v1 + with: + name: ecs-nakama-stack + template: top.yaml + capabilities: "CAPABILITY_NAMED_IAM,CAPABILITY_IAM" + parameter-overrides: VpcId=${{ secrets.VPC_ID }},Domain=${{ secrets.DOMAIN }},SubDomain=nakama,PortalCertificate=${{ secrets.CERTIFICATE_ARN }},PublicSubnets=${{ secrets.SUBNET_IDS }} \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f9547b8 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cloudformation/cluster"] + path = cloudformation/cluster + url = git@github.com:josephbmanley/aws-cluster-stack.git diff --git a/cloudformation/cluster b/cloudformation/cluster new file mode 160000 index 0000000..a7d7961 --- /dev/null +++ b/cloudformation/cluster @@ -0,0 +1 @@ +Subproject commit a7d7961c271839c625718e42f7ac8d6171456892 diff --git a/cloudformation/nakama/top.yaml b/cloudformation/nakama/top.yaml index 75ad9b6..78175f4 100644 --- a/cloudformation/nakama/top.yaml +++ b/cloudformation/nakama/top.yaml @@ -21,15 +21,16 @@ Parameters: #------------------- # ECS Configuration #------------------- - EcsCluster: + EcsClusterOverride: Type: String - Description: The cluster to run the Nakama service on. + Description: The cluster to run the Nakama service on, if empty will create new cluster + Default: "" #----------------- # Load Balancing #----------------- PublicSubnets: - Description: The public subnets for the ALB to run in. + Description: The public subnets for the ALB to run in. (Seperate by spaces) Type: String PortalCertificate: Description: Arn of AWS Certificate @@ -111,6 +112,7 @@ Parameters: Conditions: CreateRdsStack: !Equals [!Ref CreateDatabase, "true"] CreateDns: !Not [!Equals [!Ref Domain, ""]] + CreateCluster: !Equals [!Ref EcsClusterOverride, ""] Resources: @@ -154,14 +156,28 @@ Resources: LoadBalancing: Type: AWS::CloudFormation::Stack Properties: - TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/${release}/cloudformation/nakama/load_balancing.yaml' + TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/nakama/${release}/cloudformation/nakama/load_balancing.yaml' Parameters: environment: !Ref environment release: !Ref release VpcId: !Ref VpcId - PublicSubnets: !Ref PublicSubnets + PublicSubnets: !Join [",", !Split [" ", !Ref PublicSubnets]] PortalCertificate: !Ref PortalCertificate + #------------- + # ECS Cluster + #------------- + EcsCluster: + Condition: CreateCluster + Type: AWS::CloudFormation::Stack + Properties: + TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/nakama/${release}/cloudformation/cluster/top.yaml' + Parameters: + Environment: !Ref environment + VpcId: !Ref VpcId + SubnetIds: !Join [",", !Split [" ", !Ref PublicSubnets]] + Project: "Nakama" + #------------------- # ECS Task & Service #------------------- @@ -181,7 +197,7 @@ Resources: DependsOn: LoadBalancing Type: AWS::ECS::Service Properties: - Cluster: !Ref EcsCluster + Cluster: !If ["CreateCluster", !GetAtt EcsCluster.Outputs.Cluster, !Ref EcsClusterOverride] DesiredCount: 1 TaskDefinition: !GetAtt TaskDefinition.Outputs.TaskArn LoadBalancers: