-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(docker): add Docker support and GitHub Actions workflow for Doc…
…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
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |