diff --git a/.github/workflows/deploy-api.yml b/.github/workflows/deploy-api.yml new file mode 100644 index 0000000..cf57e02 --- /dev/null +++ b/.github/workflows/deploy-api.yml @@ -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 }} diff --git a/.github/workflows/telegram-trigger.yml b/.github/workflows/telegram-trigger.yml index 8541d06..1f9fd57 100644 --- a/.github/workflows/telegram-trigger.yml +++ b/.github/workflows/telegram-trigger.yml @@ -2,7 +2,8 @@ name: Telegram Trigger Workflow on: push: - branches: [polinom] + branches: + - polinom jobs: send-inline-message: diff --git a/Dockerfile.api b/Dockerfile.api new file mode 100644 index 0000000..1f2b5d6 --- /dev/null +++ b/Dockerfile.api @@ -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" ] diff --git a/Dockerfile.web b/Dockerfile.web new file mode 100644 index 0000000..1889e90 --- /dev/null +++ b/Dockerfile.web @@ -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" ] diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 3187d6a..ae2e923 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -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}`, diff --git a/apps/web/next.config.js b/apps/web/next.config.js index 2683e40..5a14519 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -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