Skip to content

Commit 36136a6

Browse files
authored
Merge branch 'main' into #156-move-rooms-to-the-past-room-list-and-change-settlestatus-automatically-when-the-participant-is-one
2 parents 97a4ad5 + f76afb1 commit 36136a6

12 files changed

+155
-32
lines changed
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Create Release and Tag
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
branches:
7+
- main
8+
9+
jobs:
10+
if_merged:
11+
if: github.event.pull_request.merged == true
12+
name: Create Release and Tag
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Get previous tag-version
22+
id: previous_tag
23+
uses: WyriHaximus/github-action-get-previous-tag@v1
24+
with:
25+
fallback: 1.0.0
26+
27+
- name: Get next minor tag-version
28+
id: minor_tag
29+
uses: WyriHaximus/github-action-next-semvers@v1
30+
with:
31+
version: ${{ steps.previous_tag.outputs.tag }}
32+
33+
- name: Get current time
34+
uses: josStorer/[email protected]
35+
id: date
36+
with:
37+
format: YYYY-MM-DD
38+
utcOffset: "+09:00"
39+
40+
- name: Create Release
41+
id: create_release
42+
uses: actions/create-release@v1
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
with:
46+
tag_name: ${{ steps.minor_tag.outputs.v_patch }}
47+
release_name: ${{ steps.minor_tag.outputs.v_patch }}
48+
body: |
49+
${{ steps.date.outputs.formattedTime }}
50+
Github action released ${{ steps.minor_tag.outputs.v_patch }}
51+
draft: false
52+
prerelease: false

.github/workflows/push_image_ecr.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Push Image to Amazon ECR
2+
3+
# when tagging action success
4+
on:
5+
workflow_run:
6+
workflows: ["Create Release and Tag"]
7+
types:
8+
- completed
9+
10+
env:
11+
AWS_REGION: ap-northeast-2
12+
13+
jobs:
14+
if_workflow_success:
15+
name: Build and Push
16+
runs-on: ubuntu-latest
17+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Get previous tag-version
26+
id: previous_tag
27+
uses: WyriHaximus/github-action-get-previous-tag@v1
28+
with:
29+
fallback: 1.0.0
30+
31+
- name: Set Tag Version
32+
id: tag
33+
uses: actions/github-script@v4
34+
with:
35+
script: |
36+
const tagVersion = "${{ steps.previous_tag.outputs.tag }}".replace('v', '')
37+
core.setOutput('tag', tagVersion)
38+
39+
- name: Configure AWS credentials
40+
uses: aws-actions/configure-aws-credentials@v1
41+
with:
42+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
43+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
44+
aws-region: ${{ env.AWS_REGION }}
45+
46+
- name: Login to AWS ECR
47+
id: login-ecr
48+
uses: aws-actions/amazon-ecr-login@v1
49+
50+
- name: Build and Push to AWS ECR
51+
id: build_image
52+
env:
53+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
54+
IMAGE_TAG: ${{ steps.tag.outputs.tag }}
55+
ECR_REPOSITORY: taxi-back
56+
run: |
57+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
58+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
59+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
60+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
61+
echo "Push iamge : $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG and latest"

.github/workflows/node.js.yml .github/workflows/test_ci.yml

+6-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 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
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3-
name: Node.js CI
3+
name: Test for Continuous integration
44
on:
55
push:
66
branches: [ "main" ]
@@ -19,34 +19,16 @@ jobs:
1919
run: sudo docker run --name mongodb -d -p 27017:27017 mongo:${{ matrix.mongodb-version }}
2020
- name: Use Node.js ${{ matrix.node-version }}
2121
uses: actions/checkout@v3
22+
with:
23+
submodules: true
2224
- name: Setup Node
2325
uses: actions/setup-node@v3
2426
with:
2527
node-version: ${{ matrix.node-version }}
2628
cache: 'npm'
27-
- name: Install aws cli
28-
run: sudo apt update && sudo apt install awscli
29-
- name: create AWS configuration file and copy
30-
run: |
31-
mkdir -p ~/.aws
32-
cd ~/.aws
33-
pwd
34-
touch credentials
35-
echo "[default]" >> credentials
36-
echo aws_access_key_id = ${{ secrets.AWS_ACCESS_KEY_ID }} >> credentials
37-
echo aws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }} >> credentials
38-
cat credentials
39-
touch config
40-
echo "[default]" >> config
41-
echo "region = ap-northeast-2" >> config
42-
echo "output = json" >> config
43-
- name: Download mongoDB dump file
44-
run: aws s3 cp --recursive s3://${{ secrets.AWS_S3_BUCKET_NAME }}/dump dump
45-
- name: Copy to mongodb container
46-
run: docker cp dump mongodb:/dump
47-
- name: Restore DB from dump file
48-
run: docker exec mongodb sh -c 'mongorestore ${{ secrets.DB_PATH }} /dump/${{ secrets.DB_NAME }}'
49-
- name: Install dependencies from package-lock.json
29+
- name: Install sampleGenerator dependencies from package-lock.json
30+
run: cd sampleGenerator && npm ci && cd ..
31+
- name: Install taxi-back dependencies from package-lock.json
5032
run: npm ci
5133
- name: Run unit tests
5234
run: npm test

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "sampleGenerator"]
2+
path = sampleGenerator
3+
url = https://github.com/sparcs-kaist/taxiSampleGenerator

Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:16-alpine
2+
3+
# Copy repository
4+
WORKDIR /usr/src/app
5+
COPY . .
6+
7+
# Install requirements
8+
RUN npm ci
9+
10+
# Run container
11+
EXPOSE 80
12+
ENV PORT 80
13+
CMD ["npm", "run", "serve"]

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141
},
4242
"scripts": {
4343
"start": "npx nodemon app.js",
44-
"test": "cross-env TZ='Asia/Seoul' NODE_ENV=test mocha --recursive --reporter spec --exit",
44+
"test": "npm run sample && npm run mocha",
45+
"mocha": "cross-env TZ='Asia/Seoul' NODE_ENV=test mocha --recursive --reporter spec --exit",
4546
"serve": "cross-env TZ='Asia/Seoul' NODE_ENV=production node app.js",
46-
"lint": "npx eslint --fix ."
47+
"lint": "npx eslint --fix .",
48+
"sample": "cd sampleGenerator && npm start && cd .."
4749
},
4850
"author": "sparcs/taxi",
4951
"license": "MIT"

sampleGenerator

Submodule sampleGenerator added at 374f7b1

src/auth/login.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const getLoginInfo = (req) => {
44
if (req.session.loginInfo) {
55
const { id, sid, name, time } = req.session.loginInfo;
66
const timeFlow = Date.now() - time;
7-
if (timeFlow > 3600000)
7+
if (timeFlow > 14 * 24 * 3600 * 1000)
88
return { id: undefined, sid: undefined, name: undefined };
99
else {
1010
req.session.loginInfo.time = Date.now();

src/db/mongo.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ const roomSchema = Schema({
5656
const locationSchema = Schema({
5757
enName: { type: String, required: true },
5858
koName: { type: String, required: true },
59-
// latitude: { type: Number, required: true },
59+
priority: { type: Number, default: 0 },
60+
isValid: { type: Boolean, default: true },
61+
// latitude: { type: Number, required: true },
6062
// longitude: { type: Number, required: true }
6163
});
6264
const chatSchema = Schema({

src/service/locations.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ const logger = require("../modules/logger");
33

44
const getAllLocationsHandler = async (_, res) => {
55
try {
6-
const locations = await locationModel.find({}, { __v: 0 });
6+
const locations = await locationModel
7+
.find(
8+
{
9+
isValid: { $ne: false },
10+
},
11+
{ __v: 0 }
12+
)
13+
.sort({ priority: 1 });
714
const serverTime = new Date().toISOString();
815
res.json({ locations, serverTime });
916
} catch (err) {

src/service/rooms.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ const searchHandler = async (req, res) => {
303303

304304
// 검색 시간대는 해당 날짜의 자정으로 설정합니다.
305305
const maxTime = new Date(minTime);
306-
maxTime.setDate(minTime.getDate() + 1);
306+
maxTime.setDate(minTime.getDate() + (time ? 1 : 14));
307307
maxTime.setHours(0);
308308
maxTime.setMinutes(0);
309309
maxTime.setSeconds(0);

test/logininfo.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe("logininfo handler", function () {
4747
id: "hello-id",
4848
sid: "hello-sid",
4949
name: "hello-name",
50-
time: new Date(Date.now() - (3600 * 1000 + 1)).getTime(), // the session should expire after 1 hour
50+
time: new Date(Date.now() - (14 * 24 * 3600 * 1000 + 1)).getTime(), // the session should expire after 1 hour
5151
},
5252
},
5353
};
@@ -119,7 +119,7 @@ describe("detail info handler", function () {
119119
id: "hello-id",
120120
sid: "hello-sid",
121121
name: "hello-name",
122-
time: new Date(Date.now() - (3600 * 1000 + 1)).getTime(), // the session should expire after 1 hour
122+
time: new Date(Date.now() - (14 * 24 * 3600 * 1000 + 1)).getTime(), // the session should expire after 1 hour
123123
},
124124
},
125125
};

0 commit comments

Comments
 (0)