Skip to content

Commit

Permalink
add Dockerfile and build workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
fisher60 committed Apr 9, 2024
1 parent 978881d commit 2db4162
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build

on:
workflow_call:
inputs:
latest:
description: "If the container should be tagged as latest."
type: boolean
required: false
default: false
push:
description: "If the built container should be pushed."
type: boolean
required: false
default: false

jobs:
build:
name: Build docker image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Github Container Registry
if: ${{ inputs.push }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create SHA Container Tag
id: sha_tag
run: |
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
echo "::set-output name=tag::$tag"
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: ${{ inputs.push }}
tags: |
ghcr.io/abandontech/abandontechsite:${{ steps.sha_tag.outputs.tag }}
${{ inputs.latest && 'ghcr.io/abandontech/abandontechsite:latest' || '' }}
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Main

on:
push:
branches: main

jobs:
build:
uses: ./.github/workflows/build.yml
with:
latest: true
push: true
13 changes: 13 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Pull Request

on:
pull_request:
branches: main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
uses: ./.github/workflows/build.yml
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM node:20 as deps

WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock ./
RUN yarn install

FROM node:20-alpine AS builder

WORKDIR /build

COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN yarn run nuxt build

FROM builder AS runner

WORKDIR /app

ENV NODE_ENV=production

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nuxt -u 1001

COPY --from=builder /build/.output ./.output

USER nuxt

EXPOSE 3000

CMD ["node", ".output/server/index.mjs"]

0 comments on commit 2db4162

Please sign in to comment.