diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b6e0dbc --- /dev/null +++ b/.dockerignore @@ -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 \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..60a6171 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a2c53d9 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index 830985e..922f312 100644 --- a/README.md +++ b/README.md @@ -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 + ``` + +5. To stop the container: + ``` + docker stop + ``` + +Replace `` 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.