Skip to content

Commit

Permalink
build(docker): add Docker support and GitHub Actions workflow for Doc…
Browse files Browse the repository at this point in the history
…ker image publishing

Add a `.dockerignore` file to exclude unnecessary files from the Docker build context, reducing image size and build time. Introduce a `Dockerfile` to define the Docker image for the application, using Node.js 18-alpine for a lightweight base image. The Dockerfile installs dependencies, builds the application, and sets the command to start the app.

Create a GitHub Actions workflow (`docker-publish.yml`) to automate the building and publishing of Docker images to the GitHub Container Registry. The workflow triggers on new tags, builds the Docker image, and pushes it with both `latest` and version-specific tags. This setup streamlines the deployment process and ensures consistent and reproducible builds.
  • Loading branch information
mauvehed committed Dec 7, 2024
1 parent eab666b commit db45a0c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
npm-debug.log
.git
Dockerfile
docker-compose.yml
*.env
build-version.json
35 changes: 35 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish Docker

on:
push:
tags:
- 'v*'

jobs:
build-and-push:
runs-on: ubuntu-latest

permissions:
packages: write
contents: read

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: mauvehed
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker Image
run: |
docker build -t ghcr.io/${{ github.repository_owner }}/yourip-app:latest .
docker tag ghcr.io/${{ github.repository_owner }}/yourip-app:latest ghcr.io/${{ github.repository_owner }}/yourip-app:${{ github.ref_name }}
- name: Push Docker Image
run: |
docker push ghcr.io/${{ github.repository_owner }}/yourip-app:latest
docker push ghcr.io/${{ github.repository_owner }}/yourip-app:${{ github.ref_name }}
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use a Node.js base image
FROM node:18-alpine

# Set working directory
WORKDIR /app

# Copy package.json and package-lock.json (or yarn.lock)
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy application files
COPY . .

# Build the application
RUN npm run build

# Expose the port your app runs on
EXPOSE 3000

# Start the application
CMD ["npm", "run", "start"]

0 comments on commit db45a0c

Please sign in to comment.