Skip to content

Commit

Permalink
feat: add docker build for deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
olemathias committed Sep 13, 2024
1 parent cd6e079 commit 01ed33d
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 12 deletions.
27 changes: 27 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# build output
dist/

# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# environment variables
.env
.env.production

# macOS-specific files
.DS_Store

# jetbrains setting folder
.idea/

# other files
/public/videos/tgno-header.mp4
39 changes: 39 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: build-image

on:
push:
branches:
- 'main'
- 'prodbuild'

jobs:
ci:
uses: ./.github/workflows/ci.yaml
build-image:
name: build image
runs-on: ubuntu-latest
needs: [ci] # require tests to pass before build runs
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build astro image for amd64
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
build-args: |
APP_ENV=production
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ci

on:
push:
branches:
- '*'
- '!main'
- '!prodbuild'
workflow_call:

jobs:
build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image for amd64 and arm64
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:lts AS base

FROM base AS prod-build
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY package.json pnpm-lock.yaml /app/
WORKDIR /app
RUN pnpm install --prod
COPY . /app
RUN pnpm run build

FROM base
WORKDIR /app
RUN chown node:node /app
USER node
COPY --from=prod-build --chown=node:node /app/node_modules /app/node_modules
COPY --from=prod-build --chown=node:node /app/dist /app/dist

ENV HOST=0.0.0.0
ENV PORT=8080
EXPOSE 8080
CMD node /app/dist/server/entry.mjs

Check warning on line 23 in Dockerfile

View workflow job for this annotation

GitHub Actions / ci / build-test

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/

Check warning on line 23 in Dockerfile

View workflow job for this annotation

GitHub Actions / build image

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
9 changes: 8 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { defineConfig } from 'astro/config';

import tailwind from '@astrojs/tailwind';

import node from '@astrojs/node';

// https://astro.build/config
export default defineConfig({
integrations: [tailwind()]
integrations: [tailwind()],
output: 'server',

adapter: node({
mode: 'standalone'
})
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
},
"dependencies": {
"@astrojs/check": "^0.9.3",
"@astrojs/node": "^8.3.3",
"@astrojs/tailwind": "^5.1.0",
"astro": "^4.15.4",
"tailwindcss": "^3.4.11",
"typescript": "^5.6.2"
}
}
}
Loading

0 comments on commit 01ed33d

Please sign in to comment.