From 4b0298814581a1dfd6a6c976975cf7c742c73bb2 Mon Sep 17 00:00:00 2001 From: Ardeman Date: Wed, 16 Apr 2025 08:23:05 +0800 Subject: [PATCH] feat: add AWS deployment configuration and scripts --- .github/workflows/deploy.yml | 35 ++++++++++++++++++++++++++++++ deploy.sh | 3 +++ env/production.yaml | 41 ++++++++++++++++++++++++++++++++++++ template.yml | 22 +++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100755 deploy.sh create mode 100644 env/production.yaml create mode 100644 template.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..119abdd --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,35 @@ +name: Deploy to AWS Lambda via SAM + +on: + push: + branches: [main] + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24' # adjust to your Go version + + - name: Set up AWS SAM CLI + uses: aws-actions/setup-sam@v2 + + - name: Build with SAM + run: sam build + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + 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: Deploy with SAM + run: | + sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --stack-name legalgo-stack --capabilities CAPABILITY_IAM --region ${{ secrets.AWS_REGION }} \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..029f4ec --- /dev/null +++ b/deploy.sh @@ -0,0 +1,3 @@ +#!/bin/bash +sam build +sam deploy --guided \ No newline at end of file diff --git a/env/production.yaml b/env/production.yaml new file mode 100644 index 0000000..c220aeb --- /dev/null +++ b/env/production.yaml @@ -0,0 +1,41 @@ +server: + base-url: https://api.legalgo.id/core + local-url: http://localhost:3300 + port: 3300 + +jwt: + token: + expires-ttl: 1440 + secret: "5Lm25V3Qd7aut8dr4QUxm5PZUrSFs" + +postgresql: + host: legalgodb.ctuok62cmn6i.ap-southeast-1.rds.amazonaws.com + port: 5432 + driver: postgres + db: legalgonews + username: legalgo_admin + password: "K4K!2Kg7cKW6H&4A2aBy2dFCRY3Sh" + ssl-mode: disable + max-idle-connections-in-second: 600 + max-open-connections-in-second: 600 + connection-max-life-time-in-second: 600 + debug: false + +oss: + access_key_id: cf9a475e18bc7626cbdbf09709d82a64 + access_key_secret: 91f3321294d3e23035427a0ecb893ada + endpoint: sin1.contabostorage.com + bucket_name: legalgonews-dev + log_level: Error + host_url: https://sin1.contabostorage.com + public_url: https://sin1.contabostorage.com/fda98c2228f246f29a7e466b86b3b9e7 + +redis: + host: legalgocache-qn8fuh.serverless.apse1.cache.amazonaws.com + port: 6379 + db: 5 + ssl: false + max-idle-connections-in-second: 600 + max-open-connections-in-second: 600 + connection-max-life-time-in-second: 600 + debug: false diff --git a/template.yml b/template.yml new file mode 100644 index 0000000..2dd7627 --- /dev/null +++ b/template.yml @@ -0,0 +1,22 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: Go Lambda API deployed with AWS SAM + +Globals: + Function: + Timeout: 10 + +Resources: + ApiFunction: + Type: AWS::Serverless::Function + Properties: + FunctionName: legalgo-api + Handler: main + Runtime: go1.x + CodeUri: . + Events: + Api: + Type: Api + Properties: + Path: / + Method: ANY \ No newline at end of file