diff --git a/.dockerignore b/.dockerignore index e65f477..be3bb98 100644 --- a/.dockerignore +++ b/.dockerignore @@ -54,4 +54,7 @@ components.json graphql.config.ts # Development utilities -nitroping \ No newline at end of file +# nitroping # SDK needed for build + +# Include SDK for build +sdk \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index d1d9cd7..776403c 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -6,16 +6,13 @@ on: - main tags: - 'v*' - pull_request: - branches: - - main env: REGISTRY: docker.io IMAGE_NAME: productdevbook/nitroping jobs: - build: + build-amd64: runs-on: ubuntu-latest permissions: contents: read @@ -29,7 +26,6 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} @@ -41,27 +37,115 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=branch,suffix=-amd64 + type=semver,pattern={{version}},suffix=-amd64 + type=semver,pattern={{major}}.{{minor}},suffix=-amd64 + type=semver,pattern={{major}},suffix=-amd64 + type=raw,value=latest-amd64,enable={{is_default_branch}} + + - name: Build and push AMD64 Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + target: production + platforms: linux/amd64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha,scope=amd64 + cache-to: type=gha,mode=max,scope=amd64 + build-args: | + DATABASE_URL=postgresql://dummy:dummy@localhost:5432/dummy + JWT_SECRET=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef + ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef + WEBHOOK_SECRET=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef + AUTO_MIGRATE=false + + build-arm64: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push Docker image + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch,suffix=-arm64 + type=semver,pattern={{version}},suffix=-arm64 + type=semver,pattern={{major}}.{{minor}},suffix=-arm64 + type=semver,pattern={{major}},suffix=-arm64 + type=raw,value=latest-arm64,enable={{is_default_branch}} + + - name: Build and push ARM64 Docker image uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile target: production - platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} + platforms: linux/arm64 + push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=gha,scope=arm64 + cache-to: type=gha,mode=max,scope=arm64 + build-args: | + DATABASE_URL=postgresql://dummy:dummy@localhost:5432/dummy + JWT_SECRET=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef + ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef + WEBHOOK_SECRET=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef + AUTO_MIGRATE=false + + create-manifest: + runs-on: ubuntu-latest + needs: [build-amd64, build-arm64] + permissions: + contents: read + packages: write + + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata for manifest + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=raw,value=latest,enable={{is_default_branch}} - - name: Test Docker image - if: github.event_name == 'pull_request' + - name: Create and push manifest run: | - docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} --help || true \ No newline at end of file + for tag in ${{ steps.meta.outputs.tags }}; do + docker buildx imagetools create \ + --tag ${tag} \ + ${tag}-amd64 \ + ${tag}-arm64 + done \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7e84ee2..81c32f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,21 @@ RUN pnpm install --frozen-lockfile FROM base AS build +# Build arguments for environment variables needed during build +ARG DATABASE_URL +ARG JWT_SECRET +ARG ENCRYPTION_KEY +ARG WEBHOOK_SECRET +ARG AUTO_MIGRATE + +# Set environment variables for build ENV NODE_OPTIONS="--max-old-space-size=4096" +ENV DATABASE_URL=$DATABASE_URL +ENV JWT_SECRET=$JWT_SECRET +ENV ENCRYPTION_KEY=$ENCRYPTION_KEY +ENV WEBHOOK_SECRET=$WEBHOOK_SECRET +ENV AUTO_MIGRATE=$AUTO_MIGRATE + RUN pnpm run build FROM base AS dev diff --git a/package.json b/package.json index 5d532de..f2041b8 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "jsonwebtoken": "^9.0.2", "lucide-vue-next": "^0.539.0", "nitro-graphql": "^1.1.3", - "nitroping": "link:./sdk", + "nitroping": "^0.1.0", "nuxt": "^4.0.3", "pinia": "^3.0.3", "postgres": "^3.4.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8a56637..408a020 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,8 +72,8 @@ importers: specifier: ^1.1.3 version: 1.1.3(@apollo/server@4.12.2(graphql@16.11.0))(@types/node@24.3.0)(crossws@0.3.5)(graphql-tag@2.12.6(graphql@16.11.0))(graphql-ws@6.0.6(crossws@0.3.5)(graphql@16.11.0)(ws@8.18.3))(graphql@16.11.0)(h3@1.15.4)(nitropack@2.12.4(@netlify/blobs@9.1.2)(drizzle-orm@0.44.4(@opentelemetry/api@1.9.0)(postgres@3.4.7)))(typescript@5.9.2) nitroping: - specifier: link:./sdk - version: link:sdk + specifier: ^0.1.0 + version: 0.1.0 nuxt: specifier: ^4.0.3 version: 4.0.3(@netlify/blobs@9.1.2)(@parcel/watcher@2.5.1)(@types/node@24.3.0)(@vue/compiler-sfc@3.5.18)(db0@0.3.2(drizzle-orm@0.44.4(@opentelemetry/api@1.9.0)(postgres@3.4.7)))(drizzle-orm@0.44.4(@opentelemetry/api@1.9.0)(postgres@3.4.7))(eslint@9.33.0(jiti@2.5.1))(ioredis@5.7.0)(lightningcss@1.30.1)(magicast@0.3.5)(optionator@0.9.4)(rollup@4.46.2)(terser@5.43.1)(typescript@5.9.2)(vite@7.1.2(@types/node@24.3.0)(jiti@2.5.1)(lightningcss@1.30.1)(terser@5.43.1)(yaml@2.8.1))(yaml@2.8.1) @@ -5392,6 +5392,10 @@ packages: xml2js: optional: true + nitroping@0.1.0: + resolution: {integrity: sha512-iH9KhCMykSTfflB0q5lC0mYSQKsoi7lECjt2+bKyb5Cjk3XRE1vDwao0asSNwuWI0jRh5ONTopDxOl+qFAhdOw==} + engines: {node: '>=22'} + no-case@3.0.4: resolution: {integrity: sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==} @@ -12968,6 +12972,8 @@ snapshots: - supports-color - uploadthing + nitroping@0.1.0: {} + no-case@3.0.4: dependencies: lower-case: 2.0.2