Skip to content

Commit

Permalink
feat: Added docker publishing (#1)
Browse files Browse the repository at this point in the history
* feat: Added dockerfile

* feat: Now publishing dockerfile in github action
  • Loading branch information
daviroo authored Sep 6, 2024
1 parent 0bb04af commit 60292f9
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Node modules
node_modules

# Logs
npm-debug.log
logs

# Build output
dist

# Version control
.git
.gitignore

# Environment variables
.env

# IDE files
.vscode
.idea

# OS files
.DS_Store
Thumbs.db
43 changes: 43 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Docker Publish

on:
push:
branches: [ "main" ]
release:
types: [created]

env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/hxckr-webhook-handler

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

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

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ github.sha }}
${{ env.IMAGE_NAME }}:${{ github.ref_name }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use an official Node.js runtime as the base image
FROM node:18-alpine

# Set the working directory in the container
WORKDIR /app

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

# Install all dependencies (including devDependencies for building)
RUN npm install

# Copy the rest of the application code
COPY . .

# Build the TypeScript code
RUN npx tsc

# Remove devDependencies
RUN npm prune --production

# Expose the port the app runs on
EXPOSE 3000

# Set NODE_ENV to production
ENV NODE_ENV=production

# Run the application
CMD ["node", "dist/server.js"]
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,38 @@ To contribute to Webhook Handler, follow these steps:
5. Create the pull request.

Alternatively, see the GitHub documentation on [creating a pull request](https://help.github.com/articles/creating-a-pull-request/).

## Docker Setup for Local Development

To build and run the project using Docker for local development:

1. Ensure you have Docker installed on your machine.

2. Build the Docker image:
```
docker build -t webhook-handler .
```

3. Run the container:
```
docker run -p 3000:3000 -e NODE_ENV=development -v $(pwd)/src:/app/src -d webhook-handler
```

This command:
- Maps port 3000 from the container to your host
- Sets the NODE_ENV to development
- Mounts the local `src` directory to the container for live code updates

4. To view logs:
```
docker logs -f <container_id>
```

5. To stop the container:
```
docker stop <container_id>
```

Replace `<container_id>` with the actual container ID, which you can get by running `docker ps`.

Note: For hot-reloading in development, you may need to adjust the Dockerfile and use a tool like nodemon.

0 comments on commit 60292f9

Please sign in to comment.