Skip to content

Commit

Permalink
📦 Add docker deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
wei committed Nov 23, 2024
1 parent a69a166 commit 36d53cd
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/rude-beds-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"socialify": minor
---

Add docker deployment
36 changes: 36 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
*.tsbuildinfo

npm-debug.log*
yarn-debug.log*
yarn-error.log*
.env
/.next
.swc

.idea
.vercel

/public/*.wasm

.dockerignore
Dockerfile
.*
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# GitHub token
GITHUB_TOKEN=
# API URL (Use public url in edge deployments, and localhost url in non-edge deployments)
PROJECT_URL=http://localhost:3000
# Google Tag Manager ID
GTM_ID=
59 changes: 59 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Publish Docker Image

on:
workflow_dispatch:
push:
branches:
- "master"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Source: https://github.com/vercel/next.js/blob/2161d8c012dcd98eb8690814bd275d56c45bf00a/examples/with-docker/Dockerfile

FROM node:18-alpine AS base

ENV GITHUB_TOKEN=
ENV PROJECT_URL=http://localhost:3000
ENV GTM_ID=
ENV PORT=3000
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1

WORKDIR /app

COPY package.json yarn.lock* ./
COPY public ./public/
RUN yarn --frozen-lockfile

COPY . .

RUN yarn build

CMD ["yarn", "start"]

EXPOSE 3000
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
socialify:
restart: unless-stopped
build:
context: .
ports:
- "3000:3000"
env_file:
- .env
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class MyApp extends App {
/>
<meta
property="og:image"
content={`${HOST_PREFIX}/assets/socialify.png`}
content="https://socialify.git.ci/wei/socialify/png?description=1&font=Raleway&issues=1&language=1&pattern=Charlie%20Brown&pulls=1&stargazers=1&theme=Light"
/>
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content="1280" />
Expand Down

0 comments on commit 36d53cd

Please sign in to comment.