Skip to content

Commit

Permalink
chore: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
3000-2 committed Jan 14, 2025
1 parent c085fcc commit f40952a
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 4 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Deploy to Amazon ECS

on:
push:
branches: [main]
paths:
- 'api/**'
workflow_dispatch:

env:
ECR_REPOSITORY: bz-code-push-production
ECS_CLUSTER: bz-code-push-production
ECS_SERVICE: bz-code-push-production
ECS_TASK_DEFINITION: bz-code-push-production
CONTAINER_NAME: bz-code-push-production

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- 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: ap-northeast-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build and push image to ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./api
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_ENV
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_DEFINITION }} \
--query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ env.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true

# - name: Notify Slack
# uses: 8398a7/action-slack@v3
# if: always()
# with:
# status: ${{ job.status }}
# fields: repo,message,commit,author,action,eventName,ref,workflow,job,took
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
100 changes: 100 additions & 0 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"express": "^4.21.2",
"express-domain-middleware": "0.1.0",
"express-rate-limit": "^7.4.0",
"ioredis": "^5.4.1",
"multer": "^1.4.5-lts.1",
"node-deepcopy": "0.1.1",
"passport": "^0.6.0",
Expand Down
4 changes: 1 addition & 3 deletions api/script/default-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as bodyParser from "body-parser";
const domain = require("express-domain-middleware");
import * as express from "express";
import * as q from "q";
import { RedisS3Storage } from './storage/redis-s3-storage';
import { RedisS3Storage } from "./storage/redis-s3-storage";

interface Secret {
id: string;
Expand All @@ -37,8 +37,6 @@ function bodyParserErrorHandler(err: any, req: express.Request, res: express.Res

export function start(done: (err?: any, server?: express.Express, storage?: Storage) => void, useJsonStorage?: boolean): void {
let storage: Storage;
let isKeyVaultConfigured: boolean;
let keyvaultClient: any;

q<void>(null)
.then(async () => {
Expand Down
9 changes: 8 additions & 1 deletion api/script/storage/redis-s3-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ export class RedisS3Storage implements storage.Storage {
private updatesDir: string = path.join(__dirname, "updates");

constructor() {
this.redisClient = new Redis();
this.redisClient = new Redis({
host: process.env.REDIS_HOST || "localhost",
port: Number.parseInt(process.env.REDIS_PORT || "6379"),
retryStrategy: (times: number) => {
const delay = Math.min(times * 50, 2000);
return delay;
},
});
this.s3Client = new S3Client({
region: process.env.AWS_REGION,
credentials: {
Expand Down

0 comments on commit f40952a

Please sign in to comment.