diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml new file mode 100644 index 0000000..9fac450 --- /dev/null +++ b/.github/workflows/docker-build-push.yml @@ -0,0 +1,69 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + pull_request: + branches: + - main + release: + types: [published] + workflow_dispatch: + +env: + REGISTRY: docker.io + IMAGE_NAME: dansplugins/dansplugins-dot-com + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # Tag strategy: + # - Branch pushes: branch name (e.g., main) + # - Pull requests: pr- (build only, not pushed) + # - Releases: semver tags (e.g., 0.9.0, 0.9, 0) + # - All events: sha- for traceability + # - Main branch: 'latest' tag + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: linux/amd64,linux/arm64 diff --git a/README.md b/README.md index 1aef93e..4927220 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,49 @@ Alternatively, you could execute the `down.sh` script in the project directory: ./down.sh ``` +## Continuous Deployment + +This repository is configured with GitHub Actions for automatic Docker image builds and deployments. + +### Docker Image + +The Docker image is automatically built and pushed to Docker Hub whenever changes are pushed to the `main` branch or when a new release is published. + +**Docker Hub Repository:** `dansplugins/dansplugins-dot-com` + +### Available Tags + +The following tags are available on Docker Hub: +- `latest` - Latest build from the main branch +- `main` - Latest build from the main branch +- `sha-` - Specific commit SHA (e.g., `sha-abc1234`) +- Version tags - Semantic versioned releases (e.g., `1.2.3`, `1.2`, `1` without 'v' prefix) + +Note: Pull requests trigger builds for validation but images are not pushed to Docker Hub. + +### Pulling the Image + +To pull and run the latest Docker image: + +```bash +docker pull dansplugins/dansplugins-dot-com:latest +docker run -p 3000:3000 dansplugins/dansplugins-dot-com:latest +``` + +### GitHub Actions Workflow + +The workflow is triggered by: +- Pushes to the `main` branch +- Pull requests to the `main` branch (build only, no push) +- Published releases +- Manual workflow dispatch + +### Setup Requirements + +For the CI/CD pipeline to work, the following secrets must be configured in the GitHub repository: +- `DOCKER_USERNAME` - Docker Hub username +- `DOCKER_PASSWORD` - Docker Hub password or access token + ## Next.js This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).