diff --git a/.github/workflows/aws-ecr-push.yml b/.github/workflows/aws-ecr-push.yml new file mode 100644 index 0000000..410b7c8 --- /dev/null +++ b/.github/workflows/aws-ecr-push.yml @@ -0,0 +1,40 @@ +name: push to ECR + +on: + push: + branches: + - main + +env: + AWS_REGION: ap-northeast-2 + ECR_REPOSITORY: ticketing-queuing-ecr + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ECR_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_ECR_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build, tag, and push image to Amazon ECR + id: build-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:v$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest . + docker push $ECR_REGISTRY/$ECR_REPOSITORY --all-tags + echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:v$IMAGE_TAG" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..9f2a556 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,31 @@ +name: Test + +on: push + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '20' + + - name: check dependency cache + uses: actions/cache@v3 + id: npm-cache + with: + path: ${{ github.workspace }}/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: install dependencies + if: steps.npm-cache.outputs.cache-hit != 'true' + run: npm install + + - name: Run Test + run: npm run test diff --git a/Dockerfile b/Dockerfile index f5b6aa4..a0c2443 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18 +FROM node:20 WORKDIR /usr/src/app diff --git a/package.json b/package.json index 46883e8..bd08a90 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "start:api": "node src/api.js", "start:job": "node src/job.js", - "test": "jest" + "test": "jest --forceExit" }, "keywords": [], "author": "", diff --git a/src/api.js b/src/api.js index 72096c0..b683ab7 100644 --- a/src/api.js +++ b/src/api.js @@ -11,18 +11,20 @@ function startServer() { expressLoader(app) Logger.info('Express loaded') - app.listen(config.port, (err) => { - if (err) { - Logger.error(err) - process.exit(1) - } - Logger.info(` - ---------------------------------------------- - 🛡️ Server listening on port: ${config.port} 🛡️ - NODE_ENV: ${config.NODE_ENV} - ---------------------------------------------- - `) - }) + if (config.NODE_ENV !== 'test') { + app.listen(config.port, (err) => { + if (err) { + Logger.error(err) + process.exit(1) + } + Logger.info(` + ---------------------------------------------- + 🛡️ Server listening on port: ${config.port} 🛡️ + NODE_ENV: ${config.NODE_ENV} + ---------------------------------------------- + `) + }) + } module.exports = app } diff --git a/src/services/ticketStore.js b/src/services/ticketStore.js index e808641..d6c8004 100644 --- a/src/services/ticketStore.js +++ b/src/services/ticketStore.js @@ -75,6 +75,7 @@ module.exports = class TicketStore { userId, } } + async shiftFromWaiting(eventId, moveCount) { const results = await this._shift(this.getWaitingKeyByEventId(eventId), moveCount) return results.map((e) => ({ diff --git a/test/integrationTest/api/ticket.spec.js b/test/integrationTest/api/ticket.spec.js index 5fb1e11..83aeec3 100644 --- a/test/integrationTest/api/ticket.spec.js +++ b/test/integrationTest/api/ticket.spec.js @@ -9,6 +9,7 @@ chai.use(chaiHttp) const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) describe('Ticket', () => { + let container = null let server = null let redis = null let ticketStoreService = null diff --git a/test/integrationTest/job/jobService.spec.js b/test/integrationTest/job/jobService.spec.js index 99f4183..da1ed4b 100644 --- a/test/integrationTest/job/jobService.spec.js +++ b/test/integrationTest/job/jobService.spec.js @@ -10,6 +10,7 @@ describe('Ticket', () => { let redis = null let ticketStoreService = null let jobService = null + let container = null const testEventId = 1