Skip to content

feat(ci): setup circleci #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: 2.1

jobs:
publish-image:
docker:
- image: cimg/aws:2023.01
environment:
CODEARTIFACT_ENV: PROD
ECR_ENV: QA
SERVICE_NAME: "anticorruption-layer"
OUT_DIR: "buildscripts"
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: "Setup deploy scripts"
command: |
git clone -b v1.4 https://github.com/topcoder-platform/tc-deploy-scripts ../${OUT_DIR}
cp ./../${OUT_DIR}/awsconfiguration.sh .
- run:
name: "Authenticate with AWS CodeArtifact and Build Docker Image"
command: |
./awsconfiguration.sh ${CODEARTIFACT_ENV}
source awsenvconf
aws codeartifact login --tool npm --repository topcoder-framework --domain topcoder --domain-owner $AWS_ACCOUNT_ID --region $AWS_REGION --namespace @topcoder-framework
cp ~/.npmrc .
rm -f awsenvconf
docker build -t ${SERVICE_NAME}:${CIRCLE_SHA1} .
- run:
name: "Set AWS environment variables"
command: |
./awsconfiguration.sh ${ECR_ENV}
- run:
name: "Publish docker image"
command: |
source awsenvconf
aws ecr get-login-password | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
docker tag ${SERVICE_NAME}:${CIRCLE_SHA1} $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/${SERVICE_NAME}:${CIRCLE_SHA1}
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/${SERVICE_NAME}:${CIRCLE_SHA1}

workflows:
version: 2
publish:
jobs:
- "publish-image":
context: "org-global"
filters:
branches:
only: "feature/circleci-setup"
32 changes: 19 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
FROM node:18.11.0-alpine3.16 as ts-compile
WORKDIR /usr/tc-acl
FROM node:18.14.1-alpine3.17 as ts-compile
WORKDIR /usr/anticorruption-layer
COPY yarn*.lock ./
COPY package*.json ./
COPY tsconfig*.json ./
RUN npm install
COPY .npmrc ./
RUN yarn install --frozen-lockfile --production=false
COPY . ./
RUN npm run build:app
RUN yarn build:app

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

FROM gcr.io/distroless/nodejs:18
WORKDIR /usr/tc-acl
COPY --from=ts-remove /usr/tc-acl ./
WORKDIR /usr/anticorruption-layer
COPY --from=ts-remove /usr/anticorruption-layer ./
USER 1000
ENV GRPC_SERVER_PORT=40020
ENV GRPC_SERVER_HOST=localhost
ENV GRPC_RDB_SERVER_HOST=localhost
ENV GRPC_RDB_SERVER_PORT=9090
CMD ["server.js"]


18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"license": "ISC",
"dependencies": {
"@grpc/grpc-js": "^1.7.1",
"@topcoder-framework/client-relational": "v0.4.23-ci.0",
"@topcoder-framework/lib-common": "^0.4.24-ci.0",
"@topcoder-framework/client-relational": "^0.4.3",
"@topcoder-framework/lib-common": "^0.4.3",
"dayjs": "^1.11.5",
"dotenv": "^16.0.3",
"grpc-server-reflection": "^0.1.5",
Expand All @@ -28,21 +28,21 @@
"uuidv4": "^6.2.13"
},
"devDependencies": {
"@types/lodash": "^4.14.186",
"@types/node": "18.11.18",
"ts-node-dev": "^2.0.0",
"ts-proto": "^1.126.1",
"typescript": "^4.9.4",
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@commitlint/config-lerna-scopes": "^17.2.1",
"@types/lodash": "^4.14.186",
"@types/node": "18.11.18",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"commitlint": "^17.3.0",
"eslint": "^8.30.0",
"prettier": "^2.8.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1"
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.1",
"ts-node-dev": "^2.0.0",
"ts-proto": "^1.126.1",
"typescript": "^4.9.4"
},
"volta": {
"node": "18.13.0",
Expand Down
74 changes: 74 additions & 0 deletions src/common/Util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Row, Value as RelationalValue } from "@topcoder-framework/client-relational";
import { Operator, ScanCriteria, Value } from "@topcoder-framework/lib-common";
import _ from "lodash";

export class Util {
public static toScanCriteria(criteria: { [key: string]: any }): ScanCriteria[] {
Expand All @@ -11,4 +13,76 @@ export class Util {
} as ScanCriteria)
);
}

public static toIntValue(val: number): RelationalValue {
return {
value: {
$case: "intValue",
intValue: val,
},
};
}

public static toFloatValue(val: number): RelationalValue {
return {
value: {
$case: "floatValue",
floatValue: val,
},
};
}

public static toStringValue(val: string): RelationalValue {
return {
value: {
$case: "stringValue",
stringValue: val,
},
};
}

public static toDatetimeValue(val: string): RelationalValue {
return {
value: {
$case: "datetimeValue",
datetimeValue: val,
},
};
}

public static parseRow(row: Row): any {
const obj: any = {};
for (const key of Object.keys(row.values)) {
if (row.values[key].value?.$case) {
obj[_.camelCase(key)] = _.get(row.values[key].value, row.values[key].value!.$case);
}
}
return obj;
}

public static formatDate(str: string | undefined) {
if (str == null || str.length == 0) {
return undefined;
}
try {
let date = new Date(str);
let year = date.getFullYear();
let month = (date.getMonth() + 1).toString().padStart(2, "0");
let day = date.getDate().toString().padStart(2, "0");
let hours = date.getHours().toString().padStart(2, "0");
let minutes = date.getMinutes().toString().padStart(2, "0");
let seconds = date.getSeconds().toString().padStart(2, "0");
let milliseconds = date.getMilliseconds().toString().padStart(3, "0");

return (
[year, month, day].join("-") +
" " +
[hours, minutes, seconds].join(":") +
"." +
milliseconds
);
} catch {
return undefined;
}
}
}
2 changes: 1 addition & 1 deletion src/helper/ChallengeHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Query, QueryBuilder } from "@topcoder-framework/client-relational";
import { Util } from "../common/Util";
import { ObserverResourceInfoToAdd, ResourceInfoTypeIds } from "../config/constants";
import {
CreateChallengeInput_Phase,
Expand All @@ -11,7 +12,6 @@ import { ProjectPhaseSchema } from "../schema/project/ProjectPhase";
import { PrizeSchema } from "../schema/project_payment/Prize";
import { ResourceSchema } from "../schema/resource/Resource";
import { ResourceInfoSchema } from "../schema/resource/ResourceInfo";
import Util from "./Util";

class ChallengeHelper {
public getChallengeCreateQuery(
Expand Down
78 changes: 0 additions & 78 deletions src/helper/util.ts

This file was deleted.

Loading