Added github actions (#7)

* Added github actions

* added deploy-demo step

* Updated README

* test out deploy-demo

* finalize
This commit is contained in:
Doh
2025-01-02 18:29:31 -05:00
committed by GitHub
parent e2ae2bafa7
commit e06e6260ef
2 changed files with 112 additions and 2 deletions

71
.github/workflows/docker-publish.yml vendored Normal file
View File

@@ -0,0 +1,71 @@
name: Docker Build and Publish
on:
push:
branches:
- main
# - github-actions
jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
EXISTS: ${{ steps.check-version.outputs.EXISTS }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Get version from package.json
id: package-version
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Check if version exists
id: check-version
run: |
if docker pull dohsimpson/habittrove:v${{ steps.package-version.outputs.VERSION }} 2>/dev/null; then
echo "EXISTS=true" >> $GITHUB_OUTPUT
else
echo "EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Build Docker image
run: docker build -t habittrove .
- name: Push Docker images
run: |
if [ "${{ steps.check-version.outputs.EXISTS }}" = "false" ]; then
docker tag habittrove dohsimpson/habittrove:v${{ steps.package-version.outputs.VERSION }}
docker push dohsimpson/habittrove:v${{ steps.package-version.outputs.VERSION }}
echo "Pushed tag: v${{ steps.package-version.outputs.VERSION }}"
docker tag habittrove dohsimpson/habittrove:latest
docker push dohsimpson/habittrove:latest
echo "Pushed tag: latest"
fi
docker tag habittrove dohsimpson/habittrove:dev
docker push dohsimpson/habittrove:dev
echo "Pushed tag: dev"
deploy-demo:
runs-on: ubuntu-latest
needs: build-and-push
# demo tracks the latest tag
if: needs.build-and-push.outputs.EXISTS == 'false'
steps:
- uses: actions/checkout@v4
- uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: rollout restart -n ${{ secrets.KUBE_NAMESPACE }} deploy/${{ secrets.KUBE_DEPLOYMENT }}

View File

@@ -60,16 +60,55 @@ npm run dev
## Docker Deployment
For production deployment, you can use Docker. The application data will be persisted in the `data` directory.
HabitTrove can be run using Docker in several ways, depending on your needs:
### Using Pre-built Images
The easiest way to run HabitTrove is using our pre-built Docker images from DockerHub:
1. First, prepare the data directory with correct permissions:
```bash
mkdir -p data
chown -R 1001:1001 data # Required for the nextjs user in container
```
2. Then run using either method:
```bash
# Using docker-compose (recommended)
docker compose up -d
# Or using docker run directly
docker run -d -p 3000:3000 -v ./data:/app/data dohsimpson/habittrove
```
Available image tags:
- `latest`: Stable release version, recommended for most users
- `vX.Y.Z` (e.g., `v0.1.4`): Specific version for reproducible deployments and rollbacks
- `dev`: Latest development build from the main branch, may contain unstable features
Choose your tag based on needs:
- Use `latest` for general production use
- Use version tags (e.g., `v0.1.4`) for reproducible deployments
- Use `dev` for testing new features
### Building Locally
If you want to build the image locally (useful for development):
```bash
# Build the Docker image
npm run docker-build
# Run the Docker container
# Run the container
npm run docker-run
```
The application data will be persisted in the `data` directory in both cases.
## Contributing
Contributions are welcome! We appreciate both: