Skip to content

Commit

Permalink
✨ feat: 인프라 변경을 위한 github actions 작성 (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanggwangseong committed Jan 6, 2025
1 parent 6d3b7e7 commit 07fe3d7
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: AWS deploy

on:
push:
branches:
- feature/76-infra-change-aws


jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

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

- name: Build, tag, and push image to Amazon ECR
id: build-image
uses: docker/build-push-action@v3
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.AWS_CONTAINER_REGISTRY }}
IMAGE_TAG: latest
with:
file: ./Dockerfile.ecs
context: .
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/${{ secrets.AWS_CONTAINER_REGISTRY }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
secrets: |
GIT_AUTH_TOKEN=${{ secrets.GIT_TOKEN }}
- name: Build Image Path
id: image-path
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.AWS_CONTAINER_REGISTRY }}
IMAGE_TAG: latest
run: |
echo "ecs-deploy=${{ steps.login-ecr.outputs.registry }}/${{ secrets.AWS_CONTAINER_REGISTRY }}:latest" >> $GITHUB_OUTPUT
- name: Download task definition
run: |
aws ecs describe-task-definition \
--task-definition ${{secrets.TASK_DEFINITION_NAME}} \
--query taskDefinition \
> ecs-deploy-task-definition.json
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ecs-deploy-task-definition.json
service: ${{secrets.ECS_SERVICE}}
cluster: ${{secrets.ECS_CLUSTER}}
wait-for-service-stability: true


13 changes: 13 additions & 0 deletions Dockerfile.ecs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:22-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY test.js ./

EXPOSE 3000

CMD ["node", "test.js"]
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const http = require("http");

const server = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("Hello");
});

server.listen(3000, () => {
console.log("Server running on port 3000");
});

0 comments on commit 07fe3d7

Please sign in to comment.