Skip to content
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
53 changes: 53 additions & 0 deletions .github/workflows/deploy-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build and deploy web to ECS

on:
push:
branches:
- polinom

env:
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
ECR_API_IMAGE: ${{ vars.ECR_API_IMAGE }}
ECS_CLUSTER: ${{ vars.ECS_CLUSTER }}
ECS_API_SERVICE: ${{ vars.ECS_API_SERVICE }}
jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
users: actions/checkout@v2

- name: Set up QEMU for arm64
run: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
if: runner.os == 'Linux'

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

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

- name: Login to Amazon ECR
run: |
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

- name: Build and push Docker image
run: |
docker build -t $ECR_API_IMAGE -f Dockerfile.api .
docker tag $ECR_API_IMAGE:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$ECR_API_IMAGE:latest
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$ECR_API_IMAGE:latest

- name: Deploy to ECS
uses: imehedi/actions-awscli-v2@latest
with:
args: ecs update-service --cluster $ECS_CLUSTER --service $ECS_API_SERVICE --force-new-deployment
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
3 changes: 2 additions & 1 deletion .github/workflows/telegram-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Telegram Trigger Workflow

on:
push:
branches: [polinom]
branches:
- polinom

jobs:
send-inline-message:
Expand Down
19 changes: 19 additions & 0 deletions Dockerfile.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:23.6.1-alpine3.20 AS installer
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i

FROM node:23.6.1-alpine3.20 AS builder
WORKDIR /usr/src/app
COPY --from=installer /usr/src/app/node_modules ./node_modules
COPY . .
RUN npm run api:build:development

FROM node:23.6.1-alpine3.20 AS runner
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules ./node_modules

EXPOSE 3001

CMD [ "node", "dist/apps/api/main.js" ]
20 changes: 20 additions & 0 deletions Dockerfile.web
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:23.6.1-alpine3.20 AS installer
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i

FROM node:23.6.1-alpine3.20 AS builder
WORKDIR /usr/src/app
COPY --from=installer /usr/src/app/node_modules ./node_modules
COPY . .
RUN npm run web:build:development

FROM node:23.6.1-alpine3.20 AS runner
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/dist/apps/web/.next/standalone .
COPY --from=builder /usr/src/app/dist/apps/web/public apps/web/public
COPY --from=builder /usr/src/app/dist/apps/web/.next/static dist/apps/web/.next/static

EXPOSE 3000

ENTRYPOINT [ "node", "apps/web/server.js" ]
2 changes: 1 addition & 1 deletion apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule);
const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
const port = process.env.PORT || 3000;
const port = process.env.PORT || 3001;
await app.listen(port);
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`,
Expand Down
1 change: 1 addition & 0 deletions apps/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { composePlugins, withNx } = require('@nx/next');
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
**/
const nextConfig = {
output: 'standalone',
nx: {
// Set this to true if you would like to to use SVGR
// See: https://github.com/gregberge/svgr
Expand Down