Skip to content

Commit

Permalink
feat: docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
jgryffindor authored Nov 25, 2024
1 parent e8886a4 commit 903f5b5
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__tests__
.circleci
.github
node_modules
.env.local
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ NEXT_PUBLIC_GHOSTCLOUD_DENOM=token
NEXT_PUBLIC_GHOSTCLOUD_URL_SCHEME=http
NEXT_PUBLIC_GHOSTCLOUD_URL_DOMAIN=localhost:8880
NEXT_PUBLIC_GHOSTCLOUD_GAS_PRICE=0.000000025
NEXT_PUBLIC_GHOSTCLOUD_GAS_LIMIT_MULTIPLIER=1.5
NEXT_PUBLIC_GHOSTCLOUD_GAS_LIMIT_MULTIPLIER=1.5
12 changes: 0 additions & 12 deletions .env.production.local

This file was deleted.

64 changes: 64 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build and Push Docker Image

on:
push:
branches:
- main
tags:
- '*'

jobs:
build-and-push:
runs-on: ubuntu-latest
strategy:
matrix:
environment: [dev, testnet, alpha]
environment: ${{ matrix.environment }}
steps:
- name: Checkout code
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.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Create .env file
run: |
touch .env
echo "NEXT_PUBLIC_WEB3AUTH_NETWORK=${{ vars.NEXT_PUBLIC_WEB3AUTH_NETWORK }}" >> .env
echo "NEXT_PUBLIC_WEB3AUTH_CLIENT_ID=${{ secrets.NEXT_PUBLIC_WEB3AUTH_CLIENT_ID }}" >> .env
echo "NEXT_PUBLIC_GHOSTCLOUD_RPC_TARGET=${{ vars.NEXT_PUBLIC_GHOSTCLOUD_RPC_TARGET }}" >> .env
echo "NEXT_PUBLIC_GHOSTCLOUD_CHAIN_NAMESPACE=${{ vars.NEXT_PUBLIC_GHOSTCLOUD_CHAIN_NAMESPACE }}" >> .env
echo "NEXT_PUBLIC_GHOSTCLOUD_DISPLAY_NAME=${{ vars.NEXT_PUBLIC_GHOSTCLOUD_DISPLAY_NAME }}" >> .env
echo "NEXT_PUBLIC_GHOSTCLOUD_CHAIN_ID=${{ vars.NEXT_PUBLIC_GHOSTCLOUD_CHAIN_ID }}" >> .env
echo "NEXT_PUBLIC_GHOSTCLOUD_ADDRESS_PREFIX=${{ vars.NEXT_PUBLIC_GHOSTCLOUD_ADDRESS_PREFIX }}" >> .env
echo "NEXT_PUBLIC_GHOSTCLOUD_DENOM=${{ vars.NEXT_PUBLIC_GHOSTCLOUD_DENOM }}" >> .env
echo "NEXT_PUBLIC_GHOSTCLOUD_URL_SCHEME=${{ vars.NEXT_PUBLIC_GHOSTCLOUD_URL_SCHEME }}" >> .env
echo "NEXT_PUBLIC_GHOSTCLOUD_URL_DOMAIN=${{ vars.NEXT_PUBLIC_GHOSTCLOUD_URL_DOMAIN }}" >> .env
echo "NEXT_PUBLIC_GHOSTCLOUD_GAS_PRICE=${{ vars.NEXT_PUBLIC_GHOSTCLOUD_GAS_PRICE }}" >> .env
echo "NEXT_PUBLIC_GHOSTCLOUD_GAS_LIMIT_MULTIPLIER=${{ vars.NEXT_PUBLIC_GHOSTCLOUD_GAS_LIMIT_MULTIPLIER }}" >> .env
- name: Get the Git tag
id: get_tag
run: echo "GIT_TAG=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_ENV

- name: Build and push with github release tag
if: matrix.environment == 'alpha' && startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: lifted/ghostcloud-frontend:${{ env.GIT_TAG }}

- name: Build and push with environment tag for latest images
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: lifted/ghostcloud-frontend:${{ matrix.environment }}
69 changes: 69 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# syntax=docker.io/docker/dockerfile:1

FROM oven/bun:1.1.34-slim AS base

# Install dependencies only when needed
FROM base AS deps
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json package-lock.json* pnpm-lock.yaml* .npmrc* bun.lockb ./
RUN \
if [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
elif [ -f bun.lockb ]; then bun install --no-save; \
else echo "Lockfile not found." && exit 1; \
fi

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN \
if [ -f .env* ]; then echo ".env file found, continuing..."; else echo ".env file not found, exiting..."; exit 1; fi

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED=1

RUN \
if [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
elif [ -f bun.lockb ]; then bun run build; \
else echo "Lockfile not found." && exit 1; \
fi

RUN rm -rf .env

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED=1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT=3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]

Binary file added bun.lockb
Binary file not shown.
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
reactStrictMode: true,
swcMinify: true,
typescript: {
ignoreBuildErrors: true,
},
// The following is required in order to use `yarn next export`
// experimental: {
// images: {
Expand Down

0 comments on commit 903f5b5

Please sign in to comment.