diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index bef34b86..3d0e94ed 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -11,29 +11,33 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Get package version - id: get_version - run: echo "::set-output name=version::$(jq -r .version package.json)" - - - name: Debug Pre-Build Information - run: | - docker run --rm node:latest node -v - docker run --rm node:latest npm -v - docker run --rm node:latest git --version - - - name: Build and tag Docker image - run: | - docker build . --file Dockerfile --tag codechat/api:${{ steps.get_version.outputs.version }} - docker tag codechat/api:${{ steps.get_version.outputs.version }} codechat/api:latest - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Push Docker image to Docker Hub - run: docker push codechat/api:latest + - name: Checkout code + uses: actions/checkout@v3 + + - name: Get package version + id: get_version + run: echo "::set-output name=version::$(jq -r .version package.json)" + + - name: Debug Pre-Build Information + run: | + docker run --rm node:latest node -v + docker run --rm node:latest npm -v + docker run --rm node:latest git --version + + - name: Build and tag Docker image + run: | + docker build . --file Dockerfile --tag codechat/api:${{ steps.get_version.outputs.version }} + docker tag codechat/api:${{ steps.get_version.outputs.version }} codechat/api:latest + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64,linux/arm64 + push: true + tags: codechat/api:develop diff --git a/Dockerfile b/Dockerfile index 34fa3e09..7d577f2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,19 @@ ### BASE IMAGE -FROM node:20-bullseye-slim AS base +FROM --platform=$BUILDPLATFORM node:20-bullseye-slim AS base ### BUILD IMAGE FROM base AS builder WORKDIR /codechat -COPY package*.json ./ +# Instalar dependências de construção primeiro +RUN apt-get update && apt-get install -y git -RUN apt-get update && apt-get install -y git && npm install +# Copiar arquivos package.json e instalar dependências +COPY package*.json ./ +RUN npm install +# Copiar os demais arquivos necessários para o build COPY tsconfig.json . COPY ./src ./src COPY ./public ./public @@ -18,7 +22,7 @@ COPY ./prisma ./prisma COPY ./views ./views COPY .env.dev .env -# Definindo a variável de ambiente DATABASE_URL aqui para a construção +# Definir variável de ambiente para a construção ENV DATABASE_URL=postgres://postgres:pass@localhost/db_test RUN npx prisma generate @@ -34,7 +38,7 @@ LABEL com.api.mantainer="https://github.com/code-chat-br" LABEL com.api.repository="https://github.com/code-chat-br/whatsapp-api" LABEL com.api.issues="https://github.com/code-chat-br/whatsapp-api/issues" -# Copiando arquivos construídos do estágio builder +# Copiar arquivos construídos do estágio builder COPY --from=builder /codechat/dist ./dist COPY --from=builder /codechat/docs ./docs COPY --from=builder /codechat/prisma ./prisma