Skip to content

Commit 071f776

Browse files
Merge pull request #15 from maxonchickdev/dockerfiles
added dockerfiles for api and web apps and added deploy worflow
2 parents 85cc32b + 1dd865a commit 071f776

File tree

6 files changed

+96
-2
lines changed

6 files changed

+96
-2
lines changed

.github/workflows/deploy-api.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build and deploy web to ECS
2+
3+
on:
4+
push:
5+
branches:
6+
- polinom
7+
8+
env:
9+
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
10+
ECR_API_IMAGE: ${{ vars.ECR_API_IMAGE }}
11+
ECS_CLUSTER: ${{ vars.ECS_CLUSTER }}
12+
ECS_API_SERVICE: ${{ vars.ECS_API_SERVICE }}
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
users: actions/checkout@v2
20+
21+
- name: Set up QEMU for arm64
22+
run: |
23+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
24+
if: runner.os == 'Linux'
25+
26+
- name: Set up Docker for arm64
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Configure AWS credentials
30+
uses: aws-actions/configure-aws-credentials@v2
31+
with:
32+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
33+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
34+
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
35+
36+
- name: Login to Amazon ECR
37+
run: |
38+
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
39+
40+
- name: Build and push Docker image
41+
run: |
42+
docker build -t $ECR_API_IMAGE -f Dockerfile.api .
43+
docker tag $ECR_API_IMAGE:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$ECR_API_IMAGE:latest
44+
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$ECR_API_IMAGE:latest
45+
46+
- name: Deploy to ECS
47+
uses: imehedi/actions-awscli-v2@latest
48+
with:
49+
args: ecs update-service --cluster $ECS_CLUSTER --service $ECS_API_SERVICE --force-new-deployment
50+
env:
51+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
52+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
53+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}

.github/workflows/telegram-trigger.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: Telegram Trigger Workflow
22

33
on:
44
push:
5-
branches: [polinom]
5+
branches:
6+
- polinom
67

78
jobs:
89
send-inline-message:

Dockerfile.api

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:23.6.1-alpine3.20 AS installer
2+
WORKDIR /usr/src/app
3+
COPY package*.json ./
4+
RUN npm i
5+
6+
FROM node:23.6.1-alpine3.20 AS builder
7+
WORKDIR /usr/src/app
8+
COPY --from=installer /usr/src/app/node_modules ./node_modules
9+
COPY . .
10+
RUN npm run api:build:development
11+
12+
FROM node:23.6.1-alpine3.20 AS runner
13+
WORKDIR /usr/src/app
14+
COPY --from=builder /usr/src/app/dist ./dist
15+
COPY --from=builder /usr/src/app/node_modules ./node_modules
16+
17+
EXPOSE 3001
18+
19+
CMD [ "node", "dist/apps/api/main.js" ]

Dockerfile.web

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM node:23.6.1-alpine3.20 AS installer
2+
WORKDIR /usr/src/app
3+
COPY package*.json ./
4+
RUN npm i
5+
6+
FROM node:23.6.1-alpine3.20 AS builder
7+
WORKDIR /usr/src/app
8+
COPY --from=installer /usr/src/app/node_modules ./node_modules
9+
COPY . .
10+
RUN npm run web:build:development
11+
12+
FROM node:23.6.1-alpine3.20 AS runner
13+
WORKDIR /usr/src/app
14+
COPY --from=builder /usr/src/app/dist/apps/web/.next/standalone .
15+
COPY --from=builder /usr/src/app/dist/apps/web/public apps/web/public
16+
COPY --from=builder /usr/src/app/dist/apps/web/.next/static dist/apps/web/.next/static
17+
18+
EXPOSE 3000
19+
20+
ENTRYPOINT [ "node", "apps/web/server.js" ]

apps/api/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function bootstrap() {
1212
const app = await NestFactory.create(AppModule);
1313
const globalPrefix = 'api';
1414
app.setGlobalPrefix(globalPrefix);
15-
const port = process.env.PORT || 3000;
15+
const port = process.env.PORT || 3001;
1616
await app.listen(port);
1717
Logger.log(
1818
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`,

apps/web/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { composePlugins, withNx } = require('@nx/next');
66
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
77
**/
88
const nextConfig = {
9+
output: 'standalone',
910
nx: {
1011
// Set this to true if you would like to to use SVGR
1112
// See: https://github.com/gregberge/svgr

0 commit comments

Comments
 (0)