Skip to content

Commit a468fb3

Browse files
authored
feat(ci): setup circleci (#7)
* fix: docker build Signed-off-by: Rakib Ansary <rakibansary@gmail.com> * feat: add circleci config to publish image to ecr Signed-off-by: Rakib Ansary <rakibansary@gmail.com> * refactor: unify utils Signed-off-by: Rakib Ansary <rakibansary@gmail.com> --------- Signed-off-by: Rakib Ansary <rakibansary@gmail.com>
1 parent b98f609 commit a468fb3

File tree

7 files changed

+306
-258
lines changed

7 files changed

+306
-258
lines changed

.circleci/config.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
version: 2.1
2+
3+
jobs:
4+
publish-image:
5+
docker:
6+
- image: cimg/aws:2023.01
7+
environment:
8+
CODEARTIFACT_ENV: PROD
9+
ECR_ENV: QA
10+
SERVICE_NAME: "anticorruption-layer"
11+
OUT_DIR: "buildscripts"
12+
steps:
13+
- checkout
14+
- setup_remote_docker:
15+
docker_layer_caching: true
16+
- run:
17+
name: "Setup deploy scripts"
18+
command: |
19+
git clone -b v1.4 https://github.com/topcoder-platform/tc-deploy-scripts ../${OUT_DIR}
20+
cp ./../${OUT_DIR}/awsconfiguration.sh .
21+
- run:
22+
name: "Authenticate with AWS CodeArtifact and Build Docker Image"
23+
command: |
24+
./awsconfiguration.sh ${CODEARTIFACT_ENV}
25+
source awsenvconf
26+
aws codeartifact login --tool npm --repository topcoder-framework --domain topcoder --domain-owner $AWS_ACCOUNT_ID --region $AWS_REGION --namespace @topcoder-framework
27+
cp ~/.npmrc .
28+
rm -f awsenvconf
29+
docker build -t ${SERVICE_NAME}:${CIRCLE_SHA1} .
30+
- run:
31+
name: "Set AWS environment variables"
32+
command: |
33+
./awsconfiguration.sh ${ECR_ENV}
34+
- run:
35+
name: "Publish docker image"
36+
command: |
37+
source awsenvconf
38+
aws ecr get-login-password | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
39+
docker tag ${SERVICE_NAME}:${CIRCLE_SHA1} $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/${SERVICE_NAME}:${CIRCLE_SHA1}
40+
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/${SERVICE_NAME}:${CIRCLE_SHA1}
41+
42+
workflows:
43+
version: 2
44+
publish:
45+
jobs:
46+
- "publish-image":
47+
context: "org-global"
48+
filters:
49+
branches:
50+
only: "feature/circleci-setup"

Dockerfile

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
FROM node:18.11.0-alpine3.16 as ts-compile
2-
WORKDIR /usr/tc-acl
1+
FROM node:18.14.1-alpine3.17 as ts-compile
2+
WORKDIR /usr/anticorruption-layer
3+
COPY yarn*.lock ./
34
COPY package*.json ./
45
COPY tsconfig*.json ./
5-
RUN npm install
6+
COPY .npmrc ./
7+
RUN yarn install --frozen-lockfile --production=false
68
COPY . ./
7-
RUN npm run build:app
9+
RUN yarn build:app
810

9-
FROM node:18.11.0-alpine3.16 as ts-remove
10-
WORKDIR /usr/tc-acl
11-
COPY --from=ts-compile /usr/tc-acl/package*.json ./
12-
COPY --from=ts-compile /usr/tc-acl/dist ./
13-
RUN npm install --omit=dev
11+
FROM node:18.14.1-alpine3.17 as ts-remove
12+
WORKDIR /usr/anticorruption-layer
13+
COPY --from=ts-compile /usr/anticorruption-layer/yarn*.lock ./
14+
COPY --from=ts-compile /usr/anticorruption-layer/package*.json ./
15+
COPY --from=ts-compile /usr/anticorruption-layer/dist ./
16+
COPY --from=ts-compile /usr/anticorruption-layer/.npmrc ./
17+
RUN yarn install --frozen-lockfile --production=false
1418

1519
FROM gcr.io/distroless/nodejs:18
16-
WORKDIR /usr/tc-acl
17-
COPY --from=ts-remove /usr/tc-acl ./
20+
WORKDIR /usr/anticorruption-layer
21+
COPY --from=ts-remove /usr/anticorruption-layer ./
1822
USER 1000
23+
ENV GRPC_SERVER_PORT=40020
24+
ENV GRPC_SERVER_HOST=localhost
25+
ENV GRPC_RDB_SERVER_HOST=localhost
26+
ENV GRPC_RDB_SERVER_PORT=9090
1927
CMD ["server.js"]
20-
21-

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"license": "ISC",
1717
"dependencies": {
1818
"@grpc/grpc-js": "^1.7.1",
19-
"@topcoder-framework/client-relational": "v0.4.23-ci.0",
20-
"@topcoder-framework/lib-common": "^0.4.24-ci.0",
19+
"@topcoder-framework/client-relational": "^0.4.3",
20+
"@topcoder-framework/lib-common": "^0.4.3",
2121
"dayjs": "^1.11.5",
2222
"dotenv": "^16.0.3",
2323
"grpc-server-reflection": "^0.1.5",
@@ -28,21 +28,21 @@
2828
"uuidv4": "^6.2.13"
2929
},
3030
"devDependencies": {
31-
"@types/lodash": "^4.14.186",
32-
"@types/node": "18.11.18",
33-
"ts-node-dev": "^2.0.0",
34-
"ts-proto": "^1.126.1",
35-
"typescript": "^4.9.4",
3631
"@commitlint/cli": "^17.3.0",
3732
"@commitlint/config-conventional": "^17.3.0",
3833
"@commitlint/config-lerna-scopes": "^17.2.1",
34+
"@types/lodash": "^4.14.186",
35+
"@types/node": "18.11.18",
3936
"@typescript-eslint/eslint-plugin": "^5.47.1",
4037
"@typescript-eslint/parser": "^5.47.1",
4138
"commitlint": "^17.3.0",
4239
"eslint": "^8.30.0",
43-
"prettier": "^2.8.1",
4440
"eslint-config-prettier": "^8.5.0",
45-
"eslint-plugin-prettier": "^4.2.1"
41+
"eslint-plugin-prettier": "^4.2.1",
42+
"prettier": "^2.8.1",
43+
"ts-node-dev": "^2.0.0",
44+
"ts-proto": "^1.126.1",
45+
"typescript": "^4.9.4"
4646
},
4747
"volta": {
4848
"node": "18.13.0",

src/common/Util.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { Row, Value as RelationalValue } from "@topcoder-framework/client-relational";
12
import { Operator, ScanCriteria, Value } from "@topcoder-framework/lib-common";
3+
import _ from "lodash";
24

35
export class Util {
46
public static toScanCriteria(criteria: { [key: string]: any }): ScanCriteria[] {
@@ -11,4 +13,76 @@ export class Util {
1113
} as ScanCriteria)
1214
);
1315
}
16+
17+
public static toIntValue(val: number): RelationalValue {
18+
return {
19+
value: {
20+
$case: "intValue",
21+
intValue: val,
22+
},
23+
};
24+
}
25+
26+
public static toFloatValue(val: number): RelationalValue {
27+
return {
28+
value: {
29+
$case: "floatValue",
30+
floatValue: val,
31+
},
32+
};
33+
}
34+
35+
public static toStringValue(val: string): RelationalValue {
36+
return {
37+
value: {
38+
$case: "stringValue",
39+
stringValue: val,
40+
},
41+
};
42+
}
43+
44+
public static toDatetimeValue(val: string): RelationalValue {
45+
return {
46+
value: {
47+
$case: "datetimeValue",
48+
datetimeValue: val,
49+
},
50+
};
51+
}
52+
53+
public static parseRow(row: Row): any {
54+
const obj: any = {};
55+
for (const key of Object.keys(row.values)) {
56+
if (row.values[key].value?.$case) {
57+
obj[_.camelCase(key)] = _.get(row.values[key].value, row.values[key].value!.$case);
58+
}
59+
}
60+
return obj;
61+
}
62+
63+
public static formatDate(str: string | undefined) {
64+
if (str == null || str.length == 0) {
65+
return undefined;
66+
}
67+
try {
68+
let date = new Date(str);
69+
let year = date.getFullYear();
70+
let month = (date.getMonth() + 1).toString().padStart(2, "0");
71+
let day = date.getDate().toString().padStart(2, "0");
72+
let hours = date.getHours().toString().padStart(2, "0");
73+
let minutes = date.getMinutes().toString().padStart(2, "0");
74+
let seconds = date.getSeconds().toString().padStart(2, "0");
75+
let milliseconds = date.getMilliseconds().toString().padStart(3, "0");
76+
77+
return (
78+
[year, month, day].join("-") +
79+
" " +
80+
[hours, minutes, seconds].join(":") +
81+
"." +
82+
milliseconds
83+
);
84+
} catch {
85+
return undefined;
86+
}
87+
}
1488
}

src/helper/ChallengeHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Query, QueryBuilder } from "@topcoder-framework/client-relational";
2+
import { Util } from "../common/Util";
23
import { ObserverResourceInfoToAdd, ResourceInfoTypeIds } from "../config/constants";
34
import {
45
CreateChallengeInput_Phase,
@@ -11,7 +12,6 @@ import { ProjectPhaseSchema } from "../schema/project/ProjectPhase";
1112
import { PrizeSchema } from "../schema/project_payment/Prize";
1213
import { ResourceSchema } from "../schema/resource/Resource";
1314
import { ResourceInfoSchema } from "../schema/resource/ResourceInfo";
14-
import Util from "./Util";
1515

1616
class ChallengeHelper {
1717
public getChallengeCreateQuery(

src/helper/util.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)