Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 60 additions & 50 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@ name: CI

on:
push:
tags: [ v* ]
branches: [ main ]
tags: [v*]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
env:
# Default registry - can be overridden by repository variables
REGISTRY: ${{ vars.REGISTRY || 'ghcr.io' }}
# Default image name - can be overridden by repository variables
IMAGE_NAME: ${{ vars.IMAGE_NAME || github.repository }}

jobs:
tests:
name: tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Run test.sh
run: |
scripts/test.sh
- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Run test.sh
run: |
scripts/test.sh

build:
name: Build
Expand All @@ -33,46 +38,51 @@ jobs:
contents: write
pull-requests: read
checks: write
needs: [ tests ]
needs: [tests]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Docker Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
- name: Docker Login
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Prepare a snapshot release
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --clean --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_CLI_EXPERIMENTAL: "enabled"
- name: golangci-lint
uses: golangci/golangci-lint-action@v6

- name: Release a new version
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_CLI_EXPERIMENTAL: "enabled"
- name: Prepare a snapshot release
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --clean --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_CLI_EXPERIMENTAL: "enabled"
REGISTRY: ${{ env.REGISTRY }}
IMAGE_NAME: ${{ env.IMAGE_NAME }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}

- name: Release a new version
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_CLI_EXPERIMENTAL: "enabled"
REGISTRY: ${{ env.REGISTRY }}
IMAGE_NAME: ${{ env.IMAGE_NAME }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
24 changes: 12 additions & 12 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ changelog:
use: github

dockers:
- image_templates: ["ghcr.io/fivexl/{{ .ProjectName }}:{{ .Version }}-amd64"]
- image_templates: ["{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-amd64"]
goos: linux
goarch: amd64
dockerfile: Dockerfile
Expand All @@ -40,13 +40,13 @@ dockers:
- --platform=linux/amd64
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/fivexl/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/fivexl/{{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=Apache-2.0
- image_templates: ["ghcr.io/fivexl/{{ .ProjectName }}:{{ .Version }}-arm64v8"]
- image_templates: ["{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-arm64v8"]
goos: linux
goarch: arm64
dockerfile: Dockerfile
Expand All @@ -55,18 +55,18 @@ dockers:
- --platform=linux/arm64/v8
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/fivexl/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/fivexl/{{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=Apache-2.0
docker_manifests:
- name_template: ghcr.io/fivexl/{{ .ProjectName }}:{{ .Version }}
- name_template: "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}"
image_templates:
- ghcr.io/fivexl/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/fivexl/{{ .ProjectName }}:{{ .Version }}-arm64v8
- name_template: ghcr.io/fivexl/{{ .ProjectName }}:latest
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-amd64"
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-arm64v8"
- name_template: "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest"
image_templates:
- ghcr.io/fivexl/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/fivexl/{{ .ProjectName }}:{{ .Version }}-arm64v8
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-amd64"
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-arm64v8"
174 changes: 174 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# Contributing to LProbe

Thank you for your interest in contributing to LProbe! This document provides guidelines for contributing to the project, including how to publish Docker images to your own GitHub Container Registry.

## Publishing Custom Docker Images

This project has been configured to allow contributors to easily publish Docker images to their own GitHub Container Registry (GHCR) space. This is useful when you want to:

- Test your changes in your own environment
- Maintain a fork with custom modifications
- Publish images for your own use or organization

### Quick Setup

To publish Docker images to your own GHCR space, follow these steps:

#### 1. Fork the Repository

First, fork the repository to your GitHub account if you haven't already.

#### 2. Configure Repository Variables

In your forked repository, set up the following repository variables:

1. Go to your repository on GitHub
2. Navigate to **Settings** → **Secrets and variables** → **Actions** → **Variables**
3. Click **New repository variable**
4. Add the following variables:

| Variable | Value | Description |
|----------|-------|-------------|
| `REGISTRY` | `ghcr.io` | The container registry to use (GHCR is recommended) |
| `IMAGE_NAME` | `yourusername/lprobe` | Your custom image name (replace `yourusername` with your GitHub username) |

**Example:**
- `REGISTRY`: `ghcr.io`
- `IMAGE_NAME`: `JohnPreston/lprobe`

#### 3. Trigger a Build

Once the variables are set, you can trigger a Docker image build by:

- **Creating a release tag**: Push a tag matching `v*` (e.g., `v1.0.0`, `v2.1.3`) to trigger a full release
- **Pushing to main branch**: This will create snapshot builds for testing

### Example Workflow

After setting up the variables, when you push a tag like `v1.0.0` to your fork:

1. The GitHub Actions workflow will automatically start
2. Docker images will be built for both `amd64` and `arm64` architectures
3. Images will be pushed to: `ghcr.io/yourusername/lprobe:v1.0.0` and `ghcr.io/yourusername/lprobe:latest`
4. Multi-architecture manifests will be created to support both platforms

### Using Your Custom Images

Once your images are built, you can pull and use them:

```bash
# Pull your custom image
docker pull ghcr.io/yourusername/lprobe:latest

# Use it in your deployments
docker run --rm ghcr.io/yourusername/lprobe:latest -url http://localhost:8080/health
```

### Alternative Registries

While GHCR is the default, you can configure the project to publish to any Docker-compatible registry:

#### Docker Hub

Set your repository variables to:
- `REGISTRY`: `docker.io`
- `IMAGE_NAME`: `yourusername/lprobe`

#### Google Container Registry (GCR)

Set your repository variables to:
- `REGISTRY`: `gcr.io`
- `IMAGE_NAME`: `your-project/lprobe`

#### Private Registries

For private registries, you'll also need to configure authentication:

1. Add your registry credentials as repository **secrets** (not variables):
- `DOCKER_USERNAME`: Your registry username
- `DOCKER_PASSWORD`: Your registry password/token

2. Update the workflow to use these secrets for authentication.

### Testing Changes Locally

Before publishing images, you can test your changes locally:

```bash
# Build the binary
go build -o lprobe *.go

# Test the binary
./lprobe -url http://localhost:8080/health

# Build Docker image locally
docker build -t lprobe:test .

# Test the Docker image
docker run --rm lprobe:test -url http://host.docker.internal:8080/health
```

### Submitting Changes Upstream

When you're ready to contribute your changes back to the upstream repository:

1. Ensure your changes follow the project's coding standards
2. Add tests if applicable
3. Update documentation as needed
4. Submit a pull request with a clear description of your changes

The configurable registry setup ensures that:
- The upstream repository continues to work with its original settings
- Your changes don't break existing functionality
- Contributors can easily test and publish their own versions

### Troubleshooting

#### Build Failures

If your builds fail, check:
1. Repository variables are correctly set
2. Your fork has the necessary permissions
3. The GoReleaser configuration is valid

#### Permission Issues

Ensure your GitHub Actions have the necessary permissions:
1. Go to **Settings** → **Actions** → **General**
2. Under **Workflow permissions**, select **Read and write permissions**

#### Image Pull Issues

If you can't pull your images:
1. Check that the images were successfully built and pushed
2. Verify your repository is public (or you have access to private repositories)
3. Ensure you're using the correct image name and tag

## General Contribution Guidelines

### Code Style

- Follow the existing code style and conventions
- Add comments for complex logic
- Ensure your code is properly tested

### Testing

- Run the test suite before submitting changes: `./scripts/test.sh`
- Add new tests for new functionality
- Ensure all tests pass

### Documentation

- Update relevant documentation when making changes
- Add clear comments for complex features
- Keep README and other docs up to date

### Pull Requests

- Create descriptive pull requests
- Link to relevant issues
- Provide clear descriptions of changes
- Be responsive to review comments

Thank you for contributing to LProbe! 🚀
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM scratch
COPY lprobe /lprobe
COPY lprobe /lprobe
10 changes: 5 additions & 5 deletions examples/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ FROM nginx:alpine
ARG LPROBE_VERSION=v0.0.6
ARG TARGETPLATFORM
RUN case ${TARGETPLATFORM} in \
"linux/amd64") LPROBE_ARCH=amd64 ;; \
"linux/arm64") LPROBE_ARCH=arm64 ;; \
"linux/amd64") LPROBE_ARCH=amd64 ;; \
"linux/arm64") LPROBE_ARCH=arm64 ;; \
esac \
&& wget -qO/bin/lprobe https://github.com/fivexl/lprobe/releases/download/${LPROBE_VERSION}/lprobe-linux-${LPROBE_ARCH} \
&& chmod +x /bin/lprobe \
&& rm -f /usr/bin/wget
&& wget -qO/bin/lprobe https://github.com/fivexl/lprobe/releases/download/${LPROBE_VERSION}/lprobe-linux-${LPROBE_ARCH} \
&& chmod +x /bin/lprobe \
&& rm -f /usr/bin/wget
HEALTHCHECK --interval=15s --timeout=5s --start-period=5s --retries=3 CMD [ "lprobe", "-mode=http", "-port=80", "-endpoint=/" ]
Loading