diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..941ce08 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,56 @@ +name: Docker Build + +on: + push: + branches: + - main + tags: + - 'v*' + pull_request: + branches: + - main + +jobs: + docker: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # Login to Docker Hub (requires DOCKER_USERNAME and DOCKER_PASSWORD secrets) + - name: Log in to Docker Hub + if: github.event_name != 'pull_request' && vars.DOCKER_ENABLED == 'true' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + # Image will be named cloud-server under your Docker Hub username + # Falls back to GitHub repository owner for local builds + images: | + ${{ secrets.DOCKER_USERNAME || github.repository_owner }}/cloud-server + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + # Only push if not a PR and DOCKER_ENABLED variable is set + push: ${{ github.event_name != 'pull_request' && vars.DOCKER_ENABLED == 'true' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/README.md b/README.md index ed41e6f..c00c0be 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,19 @@ docker compose up -d The server will be available at ws://localhost:9080/. Logs are persisted in the `./logs` directory on the host. +Alternatively, if Docker Hub publishing is configured for this repository, you can pull the pre-built image: + +```bash +# To find the Docker Hub username: +# 1. Go to the repository's Actions tab on GitHub +# 2. Look for successful "Docker Build" workflow runs +# 3. Check the workflow logs for the image name being pushed +# OR ask the repository maintainer for the Docker Hub username + +docker pull /cloud-server:latest +docker run -d -p 9080:9080 /cloud-server:latest +``` + To stop the server: ```bash @@ -108,3 +121,24 @@ server { ``` You may also want to make a systemd service file for the server, but this is left as an exercise to the reader. + +## Development + +### CI/CD + +This repository includes a GitHub Actions workflow that automatically builds and publishes Docker images: + +- **Trigger**: Automatically runs on push to `main` branch and on version tags (e.g., `v1.0.0`) +- **Image name**: `cloud-server` +- **Tags**: + - `latest` tag for main branch pushes + - Semantic version tags (e.g., `1.0.0`, `1.0`) for version tag pushes + +To enable Docker Hub publishing, configure the following repository secrets: +- `DOCKER_USERNAME`: Your Docker Hub username +- `DOCKER_PASSWORD`: Your Docker Hub password or access token + +And set this repository variable: +- `DOCKER_ENABLED`: Set to `true` to enable Docker Hub publishing + +The workflow will build the Docker image on every push and only push to Docker Hub if the `DOCKER_ENABLED` variable is set to `true`.