Skip to content

Commit

Permalink
Merge branch 'main' into #156-move-rooms-to-the-past-room-list-and-ch…
Browse files Browse the repository at this point in the history
…ange-settlestatus-automatically-when-the-participant-is-one
  • Loading branch information
Hyogyeong8 authored Nov 29, 2022
2 parents 97a4ad5 + f76afb1 commit 36136a6
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 32 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/create_release_tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Create Release and Tag
on:
pull_request:
types:
- closed
branches:
- main

jobs:
if_merged:
if: github.event.pull_request.merged == true
name: Create Release and Tag
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get previous tag-version
id: previous_tag
uses: WyriHaximus/github-action-get-previous-tag@v1
with:
fallback: 1.0.0

- name: Get next minor tag-version
id: minor_tag
uses: WyriHaximus/github-action-next-semvers@v1
with:
version: ${{ steps.previous_tag.outputs.tag }}

- name: Get current time
uses: josStorer/[email protected]
id: date
with:
format: YYYY-MM-DD
utcOffset: "+09:00"

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.minor_tag.outputs.v_patch }}
release_name: ${{ steps.minor_tag.outputs.v_patch }}
body: |
${{ steps.date.outputs.formattedTime }}
Github action released ${{ steps.minor_tag.outputs.v_patch }}
draft: false
prerelease: false
61 changes: 61 additions & 0 deletions .github/workflows/push_image_ecr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Push Image to Amazon ECR

# when tagging action success
on:
workflow_run:
workflows: ["Create Release and Tag"]
types:
- completed

env:
AWS_REGION: ap-northeast-2

jobs:
if_workflow_success:
name: Build and Push
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get previous tag-version
id: previous_tag
uses: WyriHaximus/github-action-get-previous-tag@v1
with:
fallback: 1.0.0

- name: Set Tag Version
id: tag
uses: actions/github-script@v4
with:
script: |
const tagVersion = "${{ steps.previous_tag.outputs.tag }}".replace('v', '')
core.setOutput('tag', tagVersion)
- 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: ${{ env.AWS_REGION }}

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

- name: Build and Push to AWS ECR
id: build_image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.tag.outputs.tag }}
ECR_REPOSITORY: taxi-back
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "Push iamge : $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG and latest"
30 changes: 6 additions & 24 deletions .github/workflows/node.js.yml → .github/workflows/test_ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
name: Test for Continuous integration
on:
push:
branches: [ "main" ]
Expand All @@ -19,34 +19,16 @@ jobs:
run: sudo docker run --name mongodb -d -p 27017:27017 mongo:${{ matrix.mongodb-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/checkout@v3
with:
submodules: true
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install aws cli
run: sudo apt update && sudo apt install awscli
- name: create AWS configuration file and copy
run: |
mkdir -p ~/.aws
cd ~/.aws
pwd
touch credentials
echo "[default]" >> credentials
echo aws_access_key_id = ${{ secrets.AWS_ACCESS_KEY_ID }} >> credentials
echo aws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }} >> credentials
cat credentials
touch config
echo "[default]" >> config
echo "region = ap-northeast-2" >> config
echo "output = json" >> config
- name: Download mongoDB dump file
run: aws s3 cp --recursive s3://${{ secrets.AWS_S3_BUCKET_NAME }}/dump dump
- name: Copy to mongodb container
run: docker cp dump mongodb:/dump
- name: Restore DB from dump file
run: docker exec mongodb sh -c 'mongorestore ${{ secrets.DB_PATH }} /dump/${{ secrets.DB_NAME }}'
- name: Install dependencies from package-lock.json
- name: Install sampleGenerator dependencies from package-lock.json
run: cd sampleGenerator && npm ci && cd ..
- name: Install taxi-back dependencies from package-lock.json
run: npm ci
- name: Run unit tests
run: npm test
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "sampleGenerator"]
path = sampleGenerator
url = https://github.com/sparcs-kaist/taxiSampleGenerator
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:16-alpine

# Copy repository
WORKDIR /usr/src/app
COPY . .

# Install requirements
RUN npm ci

# Run container
EXPOSE 80
ENV PORT 80
CMD ["npm", "run", "serve"]
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
},
"scripts": {
"start": "npx nodemon app.js",
"test": "cross-env TZ='Asia/Seoul' NODE_ENV=test mocha --recursive --reporter spec --exit",
"test": "npm run sample && npm run mocha",
"mocha": "cross-env TZ='Asia/Seoul' NODE_ENV=test mocha --recursive --reporter spec --exit",
"serve": "cross-env TZ='Asia/Seoul' NODE_ENV=production node app.js",
"lint": "npx eslint --fix ."
"lint": "npx eslint --fix .",
"sample": "cd sampleGenerator && npm start && cd .."
},
"author": "sparcs/taxi",
"license": "MIT"
Expand Down
1 change: 1 addition & 0 deletions sampleGenerator
Submodule sampleGenerator added at 374f7b
2 changes: 1 addition & 1 deletion src/auth/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const getLoginInfo = (req) => {
if (req.session.loginInfo) {
const { id, sid, name, time } = req.session.loginInfo;
const timeFlow = Date.now() - time;
if (timeFlow > 3600000)
if (timeFlow > 14 * 24 * 3600 * 1000)
return { id: undefined, sid: undefined, name: undefined };
else {
req.session.loginInfo.time = Date.now();
Expand Down
4 changes: 3 additions & 1 deletion src/db/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ const roomSchema = Schema({
const locationSchema = Schema({
enName: { type: String, required: true },
koName: { type: String, required: true },
// latitude: { type: Number, required: true },
priority: { type: Number, default: 0 },
isValid: { type: Boolean, default: true },
// latitude: { type: Number, required: true },
// longitude: { type: Number, required: true }
});
const chatSchema = Schema({
Expand Down
9 changes: 8 additions & 1 deletion src/service/locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ const logger = require("../modules/logger");

const getAllLocationsHandler = async (_, res) => {
try {
const locations = await locationModel.find({}, { __v: 0 });
const locations = await locationModel
.find(
{
isValid: { $ne: false },
},
{ __v: 0 }
)
.sort({ priority: 1 });
const serverTime = new Date().toISOString();
res.json({ locations, serverTime });
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/service/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ const searchHandler = async (req, res) => {

// 검색 시간대는 해당 날짜의 자정으로 설정합니다.
const maxTime = new Date(minTime);
maxTime.setDate(minTime.getDate() + 1);
maxTime.setDate(minTime.getDate() + (time ? 1 : 14));
maxTime.setHours(0);
maxTime.setMinutes(0);
maxTime.setSeconds(0);
Expand Down
4 changes: 2 additions & 2 deletions test/logininfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("logininfo handler", function () {
id: "hello-id",
sid: "hello-sid",
name: "hello-name",
time: new Date(Date.now() - (3600 * 1000 + 1)).getTime(), // the session should expire after 1 hour
time: new Date(Date.now() - (14 * 24 * 3600 * 1000 + 1)).getTime(), // the session should expire after 1 hour
},
},
};
Expand Down Expand Up @@ -119,7 +119,7 @@ describe("detail info handler", function () {
id: "hello-id",
sid: "hello-sid",
name: "hello-name",
time: new Date(Date.now() - (3600 * 1000 + 1)).getTime(), // the session should expire after 1 hour
time: new Date(Date.now() - (14 * 24 * 3600 * 1000 + 1)).getTime(), // the session should expire after 1 hour
},
},
};
Expand Down

0 comments on commit 36136a6

Please sign in to comment.