Skip to content
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
117 changes: 46 additions & 71 deletions .github/workflows/deploy-lambda-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@ name: Deploy Lambda to Dev

on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
repository_dispatch:
types: [deploy-to-test-event]
push:
branches: [ develop ]


jobs:
deploy:
name: Build and Deploy Lambda
name: Deploy Lambda Dev
runs-on: ubuntu-latest

env:
S3_BUCKET: sopt-makers-internal
STACK_NAME: playground-dev
AWS_REGION: ap-northeast-2

steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -18,97 +38,52 @@ jobs:
distribution: 'corretto'
java-version: '17'

- name: Setup Gradle cache
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_TEMP }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_TEMP }}
aws-region: ${{ secrets.AWS_REGION }}
aws-region: ${{ env.AWS_REGION }}

- name: Get application-lambda-dev.yml from AWS S3
- name: Get application config from S3
run: |
aws s3 cp \
--region ap-northeast-2 \
s3://sopt-makers-internal/dev/deploy/application-lambda-dev.yml src/main/resources/application-lambda-dev.yml
s3://${{ env.S3_BUCKET }}/dev/deploy/application-lambda-dev.yml \
src/main/resources/application-lambda-dev.yml

- name: Get Apple key from AWS S3
- name: Get Apple key from S3
run: |
aws s3 cp \
--region ap-northeast-2 \
s3://sopt-makers-internal/dev/deploy/${{ secrets.APPLE_KEY }} src/main/resources/static/${{ secrets.APPLE_KEY }}

- name: Set up QEMU for multi-platform builds
uses: docker/setup-qemu-action@v2
with:
platforms: linux/arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to ECR Public
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws

- name: Login to ECR Private
run: |
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
s3://${{ env.S3_BUCKET }}/dev/deploy/${{ secrets.APPLE_KEY }} \
src/main/resources/static/${{ secrets.APPLE_KEY }}

- name: Generate timestamp tag
id: timestamp
run: |
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
echo "IMAGE_TAG=build-$TIMESTAMP" >> $GITHUB_OUTPUT
echo "Generated image tag: build-$TIMESTAMP"
- name: Build Lambda
run: ./gradlew clean lambdaJar -x test

- name: Build Docker image with GraalVM native compilation
- name: Upload JAR to S3
run: |
docker buildx build \
--platform=linux/arm64 \
--cache-from type=gha \
--cache-to type=gha,mode=max \
-f lambda/dev.Dockerfile \
-t ${{ secrets.AWS_LAMBDA_DEV_ECR_REPO }}:${{ steps.timestamp.outputs.IMAGE_TAG }} \
--load \
.

- name: Tag and push Docker image to ECR
run: |
REPO_URI=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.AWS_LAMBDA_DEV_ECR_REPO }}

# Push with timestamp tag
docker tag ${{ secrets.AWS_LAMBDA_DEV_ECR_REPO }}:${{ steps.timestamp.outputs.IMAGE_TAG }} $REPO_URI:${{ steps.timestamp.outputs.IMAGE_TAG }}
docker push $REPO_URI:${{ steps.timestamp.outputs.IMAGE_TAG }}
# 빌드 ZIP 파일 찾기
JAR_FILE=$(ls build/distributions/*-lambda.zip | head -1)

# Push with latest tag
docker tag ${{ secrets.AWS_LAMBDA_DEV_ECR_REPO }}:${{ steps.timestamp.outputs.IMAGE_TAG }} $REPO_URI:latest
docker push $REPO_URI:latest
# 타임스탬프 생성
TIMESTAMP=$(date +"%Y%m%d-%H%M%S")
S3_KEY="lambda/playground-dev-${TIMESTAMP}-lambda.zip"

echo "IMAGE_URI=$REPO_URI:${{ steps.timestamp.outputs.IMAGE_TAG }}" >> $GITHUB_ENV
# S3 업로드
aws s3 cp "$JAR_FILE" "s3://${{ env.S3_BUCKET }}/$S3_KEY"

- name: Set up Python for SAM CLI
uses: actions/setup-python@v4
with:
python-version: '3.11'
echo "S3_KEY=$S3_KEY" >> $GITHUB_ENV

- name: Install AWS SAM CLI
run: |
pip install aws-sam-cli
- name: Install SAM CLI
uses: aws-actions/setup-sam@v2

- name: Deploy to Lambda with SAM
- name: Deploy with SAM
working-directory: ./lambda
run: |
sam deploy \
--config-env dev \
--no-confirm-changeset \
--stack-name ${{ env.STACK_NAME }} \
--no-fail-on-empty-changeset \
--parameter-overrides ImageUri=${{ env.IMAGE_URI }}
--parameter-overrides \
S3Bucket=${{ env.S3_BUCKET }} \
S3Key=${{ env.S3_KEY }}
Loading