Merge pull request #1 from neuronapp/build-and-push-docker-image

Dockerfile for server and automated build/push workflow
This commit is contained in:
Hakan Shehu
2024-10-09 20:46:45 +02:00
committed by GitHub
2 changed files with 78 additions and 0 deletions

44
.github/workflows/publish-image.yml vendored Normal file
View File

@@ -0,0 +1,44 @@
name: Build and Push Docker Image
on:
push:
tags:
- 'v*'
env:
REGISTRY: ghcr.io
SERVER_IMAGE_NAME: neuronapp/neuron/server
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Build and push Neuron server image
uses: docker/build-push-action@v5
with:
context: ./server
file: ./server/Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.SERVER_IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.SERVER_IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}

34
server/Dockerfile Normal file
View File

@@ -0,0 +1,34 @@
# Build stage
FROM node:20-alpine as builder
WORKDIR /app
COPY package*.json ./
COPY tsconfig.json ./
# Install dependencies
RUN npm ci
COPY src/ ./src/
RUN npm run build
# Production stage
FROM node:20-alpine
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install only production dependencies
RUN npm ci --only=production
# Copy built JavaScript files from builder stage
COPY --from=builder /app/dist ./dist
ENV NODE_ENV=production
EXPOSE 3000
CMD ["node", "dist/index.js"]