Created
July 3, 2025 23:35
-
-
Save k8adev/7f122e4deb83e625698aca45a20a3207 to your computer and use it in GitHub Desktop.
Github Actions for NestJs applications in arm64 architecture using Mau
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - preview | |
| jobs: | |
| deploy: | |
| name: Deploy | |
| uses: ./.github/workflows/mau.yml | |
| with: | |
| # It uses the branch name to determine the environment to deploy to. | |
| # https://docs.github.com/en/actions/how-tos/managing-workflow-runs-and-deployments/managing-deployments/managing-environments-for-deployment | |
| environment: ${{ github.ref_name == 'main' && 'Production' || 'Preview' }} | |
| secrets: inherit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM node:22.14-bullseye-slim | |
| WORKDIR /usr/src/app | |
| COPY package*.json ./ | |
| RUN apt-get update && apt-get install -y \ | |
| curl \ | |
| python3 \ | |
| make \ | |
| g++ \ | |
| && rm -rf /var/lib/apt/lists/* | |
| RUN npm install --no-audit | |
| COPY . . | |
| RUN npm run build | |
| EXPOSE 3000 | |
| CMD [ "node", "dist/main.js" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Mau | |
| on: | |
| workflow_call: | |
| inputs: | |
| environment: | |
| description: Environment to deploy | |
| required: true | |
| type: string | |
| jobs: | |
| deploy: | |
| name: ${{ inputs.environment }} | |
| environment: ${{ inputs.environment }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22.14 | |
| cache: npm | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: arm64 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| platforms: linux/arm64 | |
| - name: Setup Environment | |
| shell: bash | |
| run: | | |
| if [ "${{ github.event_name }}" == "pull_request" ]; then | |
| echo "GIT_HASH=${{ github.event.pull_request.head.sha }}" >> ${GITHUB_ENV} | |
| else | |
| echo "GIT_HASH=${GITHUB_SHA}" >> ${GITHUB_ENV} | |
| fi | |
| - name: Deploy | |
| run: npx @nestjs/mau deploy --wait-for-service-stability --dockerfile Dockerfile | |
| env: | |
| MAU_KEY: ${{ secrets.MAU_KEY }} | |
| MAU_SECRET: ${{ secrets.MAU_SECRET }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Olá, o dockerfile poderia ser mais cache-friendly para o seu repository de ACR ao introduzir mais layers:
Sobre teu CI, tu realmente precisa de QEMU e buildx? Me parece que não estão fazendo nada.
Sobre
npx @nestjs/mau deploy --wait-for-service-stability, sinceramente, tu pode abrir uma issue lá no nestjs e perguntar como faz deploy diretamente para o ACR do MAU sem precisar usar a CLI deles, tu removeria osetup-node, e só ficar um docker build e docker push.Além disso, se tu quiser manter continuar usando essa lib, tem necessidade de usar a flag
--wait-for-service-stability? Me parece desnecessário já que eventualmente vai ficar estável, n precisa queimar tempo de CI pra esperar ficar estável.Para melhorar o tempo de build do nest.js, experimente libs como swc ou tsup. Esse ultimo é útil quando teu projeto não depende de nada que precisa ser localizado por path diretamente (tipo typeorm versão 0.2), ele basicamente builda tua API como se fosse um frontend react, e te permite fazer deploy da aplicação sem um
node_modulesjunto, o que economiza muito espaço em disco. Uso muito esse jeito para lambda.