From 368796349ee608452c74a9582b526afdc57aa395 Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Mon, 14 Jul 2025 16:50:51 +0800 Subject: [PATCH] Add Docker support with CI/CD workflow and usage instructions - Added `.github/workflows/docker-image.yml` for automated Docker image build and push on version tags. - Created `Dockerfile` to containerize the application. - Updated README with instructions for running the application using Docker. --- .github/workflows/docker-image.yml | 42 ++++++++++++++++++++++++++++++ Dockerfile | 23 ++++++++++++++++ README.md | 14 ++++++++++ 3 files changed, 79 insertions(+) create mode 100644 .github/workflows/docker-image.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 00000000..bafe1601 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,42 @@ +name: docker-image + +on: + push: + tags: + - v* + +env: + APP_NAME: CLIProxyAPI + DOCKERHUB_REPO: eceasy/cli-proxy-api + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Generate App Version + run: echo APP_VERSION=`git describe --tags --always` >> $GITHUB_ENV + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + platforms: | + linux/amd64 + linux/arm64 + push: true + build-args: | + APP_NAME=${{ env.APP_NAME }} + APP_VERSION=${{ env.APP_VERSION }} + tags: | + ${{ env.DOCKERHUB_REPO }}:latest + ${{ env.DOCKERHUB_REPO }}:${{ env.APP_VERSION }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f869f0fc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM golang:1.24-alpine AS builder + +WORKDIR /app + +COPY go.mod go.sum ./ + +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux go build -o ./CLIProxyAPI ./cmd/server/ + +FROM alpine:3.22.0 + +RUN mkdir /CLIProxyAPI + +COPY --from=builder ./app/CLIProxyAPI /CLIProxyAPI/CLIProxyAPI + +WORKDIR /CLIProxyAPI + +EXPOSE 8317 + +CMD ["./CLIProxyAPI"] \ No newline at end of file diff --git a/README.md b/README.md index f8bf1380..50970292 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,20 @@ The server will relay the `loadCodeAssist`, `onboardUser`, and `countTokens` req > This feature only allows local access because I couldn't find a way to authenticate the requests. > I hardcoded `127.0.0.1` into the load balancing. +## Run with Docker + +Run the following command to login: + +```bash +docker run --rm -p 8085:8085 -v /path/to/your/config.yaml:/CLIProxyAPI/config.yaml -v /path/to/your/auth-dir:/root/.cli-proxy-api eceasy/cli-proxy-api:latest /CLIProxyAPI/CLIProxyAPI --login +``` + +Run the following command to start the server: + +```bash +docker run --rm -p 8317:8317 -v /path/to/your/config.yaml:/CLIProxyAPI/config.yaml -v /path/to/your/auth-dir:/root/.cli-proxy-api eceasy/cli-proxy-api:latest +``` + ## Contributing Contributions are welcome! Please feel free to submit a Pull Request.