Skip to content

Commit

Permalink
reduce image size
Browse files Browse the repository at this point in the history
  • Loading branch information
shineli1984 committed Aug 23, 2024
1 parent 036b9ee commit 60206e0
Show file tree
Hide file tree
Showing 36 changed files with 10,534 additions and 895 deletions.
52 changes: 11 additions & 41 deletions .github/workflows/deploy-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,16 @@ permissions: # see this: https://docs.github.com/en/actions/using-jobs/assigning

env:
AWS_REGION: us-east-2
GITHUB_TOKEN: ${{ secrets.TS_IMMUTABLE_SDK_GITHUB_TOKEN }}

jobs:
build-deploy-api:
name: Build and Deploy API
runs-on: ubuntu-latest-4-cores
steps:
- name: configure aws credentials
id: aws-credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_IMMUTABLE_NONPROD_DOCKER_ROLE }}
aws-region: ${{ env.AWS_REGION }}

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: setup
uses: ./.github/actions/setup

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ env.GITHUB_TOKEN }}

- name: Login to Amazon ECR
id: login-ecr
uses: docker/login-action@v3
with:
registry: ${{ steps.aws-credentials.outputs.aws-account-id }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- uses: hmarr/debug-action@v3

- name: build-image
run: |
INPUT_GITHUB_TOKEN=${{ env.GITHUB_TOKEN }} yarn nx run api:deploy --configuration=ci
dev_docker_build_push:
uses: immutable/im-shared-github-actions/.github/workflows/[email protected]
with:
environment: sandbox
url: "https://api.sandbox.immutable.com"
dockerfile: "./api/Dockerfile"
role-to-assume: "arn:aws:iam::783421985614:role/immutable-nonprod-docker-image-push"
role-session-name: "hub-immutable-nonprod-docker-image-push"
aws-region: "us-east-2"
secrets:
github-token: ${{ secrets.TS_IMMUTABLE_SDK_GITHUB_TOKEN }}
Binary file added api/.yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions api/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
6 changes: 4 additions & 2 deletions packages/api/Dockerfile → api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ COPY . .
# Install dependencies
RUN yarn install

RUN ls -la node_modules

# Build the TypeScript code
RUN yarn nx run api:build
RUN yarn build

# Stage 2: Run the application
FROM node:18-alpine
Expand All @@ -23,7 +25,7 @@ FROM node:18-alpine
WORKDIR /app

# Copy the built files from the builder stage
COPY --from=builder /app/packages/api .
COPY --from=builder /app .

# Expose the port the app runs on
EXPOSE 8080:8080
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 1 addition & 4 deletions packages/api/package.json → api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@
"build": "tsc",
"start": "tsx watch src/server.ts"
},
"type": "module",
"installConfig": {
"hoistingLimits": "workspaces"
}
"type": "module"
}
3 changes: 2 additions & 1 deletion packages/api/src/server.ts → api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ const packages: { [key: string]: any } = {
// TODO: newrelic
// TODO: no deployment of alpha package on flux commit
// TODO: env for production vs sandbox
// TODO: write wrapper for methods. because date/time type are just strings from JSON body
server.post('/v1/ts-sdk/v1/:pkg/:method', async (request: any, reply) => {
const { pkg, method } = request.params;
if (Object.keys(packages).indexOf(pkg) === -1) {
return reply.code(400).send({ error: 'Invalid package' });
}
return await packages[pkg][method](request.body);
return await packages[pkg][method](...request.body);

Check failure

Code scanning / CodeQL

Unvalidated dynamic method call High

Invocation of method with
user-controlled
name may dispatch to unexpected target and cause an exception.
});

server.get('/v1/heartbeat', async () => ({ status: 'ok' }));
Expand Down
30 changes: 30 additions & 0 deletions api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"compilerOptions": {
"noEmit": false,
"outDir": "./dist",
"rootDirs": ["src"],
"target": "es2022",
"module": "esnext",
"moduleResolution": "bundler",
"allowJs": false,
"removeComments": false,
"strict": true,
"forceConsistentCasingInFileNames": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"declaration": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"isolatedModules": true,
"noEmitOnError": true
},
"include": ["src"],
"exclude": ["node_modules", "dist"],
"ts-node-dev": {
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"customConditions": null
}
}
}
Loading

0 comments on commit 60206e0

Please sign in to comment.