Merge pull request #229 from kdurek/feat/update-dockerfile-and-cicd

ci: split workflows to separate files
This commit is contained in:
Mauricio Siu
2024-07-17 13:01:12 -06:00
committed by GitHub
4 changed files with 80 additions and 71 deletions

View File

@@ -1,19 +1,16 @@
name: Pull request name: Pull request
on: on:
pull_request: pull_request:
branches: branches:
- main - main
- canary - canary
push:
branches:
- main
- canary
env: env:
HUSKY: 0 HUSKY: 0
jobs: jobs:
build-app: build-app:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
@@ -24,8 +21,6 @@ jobs:
- name: Setup pnpm - name: Setup pnpm
uses: pnpm/action-setup@v4 uses: pnpm/action-setup@v4
with:
version: 8
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4 uses: actions/setup-node@v4
@@ -47,28 +42,3 @@ jobs:
- name: Run Tests - name: Run Tests
run: pnpm run test run: pnpm run test
build-and-push-docker-on-push:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Prepare .env file
run: |
cp .env.production.example .env.production
- name: Build and push Docker image using custom script
run: |
chmod +x ./docker/push.sh
./docker/push.sh ${{ github.ref_name == 'canary' && 'canary' || '' }}

35
.github/workflows/push.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
name: Push
on:
push:
branches:
- main
- canary
env:
HUSKY: 0
jobs:
build-and-push-docker-on-push:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Prepare .env file
run: |
cp .env.production.example .env.production
- name: Build and push Docker image using custom script
run: |
chmod +x ./docker/push.sh
./docker/push.sh ${{ github.ref_name == 'canary' && 'canary' || '' }}

View File

@@ -1,20 +1,38 @@
# Etapa 1: Prepare image for building
FROM node:18-slim AS base FROM node:18-slim AS base
# Install dependencies
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable && apt-get update && apt-get install -y python3 make g++ git && rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Disable husky # Disable husky
ENV HUSKY=0 ENV HUSKY=0
# Set pnpm home
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# Enable corepack
RUN corepack enable
# Set workdir
WORKDIR /app
FROM base AS base-deps
# Install dependencies only for production
RUN apt-get update && apt-get install -y python3 make g++ git && rm -rf /var/lib/apt/lists/*
# Copy install script for husky
COPY .husky/install.mjs ./.husky/install.mjs COPY .husky/install.mjs ./.husky/install.mjs
# Copy package.json and pnpm-lock.yaml # Copy package.json and pnpm-lock.yaml
COPY package.json pnpm-lock.yaml ./ COPY package.json pnpm-lock.yaml ./
FROM base-deps AS prod-deps
# Set production
ENV NODE_ENV=production
# Install dependencies only for production
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
FROM base-deps AS build
# Install dependencies only for building # Install dependencies only for building
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
@@ -22,40 +40,26 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
COPY . . COPY . .
# Build the application # Build the application
RUN pnpm run build RUN pnpm build
# Stage 2: Prepare image for production FROM base AS production
FROM node:18-slim AS production
# Disable husky # Set production
ENV HUSKY=0 ENV NODE_ENV=production
# Install dependencies only for production # Install dependencies only for production
ENV PNPM_HOME="/pnpm" RUN apt-get update && apt-get install -y curl apache2-utils && rm -rf /var/lib/apt/lists/*
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable && apt-get update && apt-get install -y curl && apt-get install -y apache2-utils && rm -rf /var/lib/apt/lists/*
WORKDIR /app
ENV NODE_ENV production
# Disable husky
ENV HUSKY=0
COPY --from=base /app/.husky/install.mjs ./.husky/install.mjs
# Copy the rest of the source code # Copy the rest of the source code
COPY --from=base /app/.next ./.next COPY --from=build /app/.next ./.next
COPY --from=base /app/dist ./dist COPY --from=build /app/dist ./dist
COPY --from=base /app/next.config.mjs ./next.config.mjs COPY --from=build /app/next.config.mjs ./next.config.mjs
COPY --from=base /app/public ./public COPY --from=build /app/public ./public
COPY --from=base /app/package.json ./package.json COPY --from=build /app/package.json ./package.json
COPY --from=base /app/drizzle ./drizzle COPY --from=build /app/drizzle ./drizzle
COPY --from=base /app/.env.production ./.env COPY --from=build /app/.env.production ./.env
COPY --from=base /app/components.json ./components.json COPY --from=build /app/components.json ./components.json
COPY --from=prod-deps /app/node_modules ./node_modules
# Install dependencies only for production
COPY package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
# Install docker # Install docker
RUN curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh && rm get-docker.sh RUN curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh && rm get-docker.sh
@@ -67,7 +71,6 @@ RUN curl -sSL https://nixpacks.com/install.sh -o install.sh \
&& ./install.sh \ && ./install.sh \
&& pnpm install -g tsx && pnpm install -g tsx
# Install buildpacks # Install buildpacks
RUN curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.32.1/pack-v0.32.1-linux.tgz" | tar -C /usr/local/bin/ --no-same-owner -xzv pack RUN curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.32.1/pack-v0.32.1-linux.tgz" | tar -C /usr/local/bin/ --no-same-owner -xzv pack

View File

@@ -158,6 +158,7 @@
"ct3aMetadata": { "ct3aMetadata": {
"initVersion": "7.25.2" "initVersion": "7.25.2"
}, },
"packageManager": "pnpm@8.15.4",
"engines": { "engines": {
"node": "^18.18.0", "node": "^18.18.0",
"pnpm": ">=8.15.4" "pnpm": ">=8.15.4"