Skip to content

Commit

Permalink
Add github action to build and publish docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
cmj2002 committed Jan 3, 2024
1 parent df9f001 commit 7beff19
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 3 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build and publish Docker image

on:
workflow_dispatch:
inputs:
GOST_VERSION:
description: 'Version of gost. If empty, the latest version will be used.'
required: false
type: string

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log into registry ${{ vars.REGISTRY }}
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ vars.REGISTRY }}
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get gost version
id: get-gost-version
run: |
if [ -z "${{ github.event.inputs.GOST_VERSION }}" ]; then
echo "GOST_VERSION=$(curl -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -s https://api.github.com/repos/ginuerzh/gost/releases/latest | jq -r '.tag_name' | cut -c 2-)" >> "$GITHUB_OUTPUT"
else
echo "GOST_VERSION=${{ github.event.inputs.GOST_VERSION }}" >> "$GITHUB_OUTPUT"
fi
# gost version must be <number>.<number>.<number>
- name: Verify gost version
id: verify-gost-version
run: |
if [[ ! "${{ steps.get-gost-version.outputs.GOST_VERSION }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid gost version: ${{ steps.get-gost-version.outputs.GOST_VERSION }}"
exit 1
fi
- name: Build Docker image
id: build-image
run: |
docker build \
--build-arg GOST_VERSION=${{ steps.get-gost-version.outputs.GOST_VERSION }} \
--tag ${{ vars.REGISTRY }}/${{ vars.IMAGE_NAME }}:latest \
--file Dockerfile \
.
- name: Get WARP client version
id: get-warp-client-version
run: |
echo "WARP_VERSION=$(docker run --rm --entrypoint='' caomingjun/warp:latest warp-cli --version | cut -d ' ' -f 2)" >> "$GITHUB_OUTPUT"
- name: Tag Docker image
id: tag-image
run: |
docker tag \
${{ vars.REGISTRY }}/${{ vars.IMAGE_NAME }}:latest \
${{ vars.REGISTRY }}/${{ vars.IMAGE_NAME }}:${{ steps.get-warp-client-version.outputs.WARP_VERSION }}-${{ steps.get-gost-version.outputs.GOST_VERSION }}
- name: Push Docker image
id: push-image
run: |
docker push ${{ vars.REGISTRY }}/${{ vars.IMAGE_NAME }}:latest
docker push ${{ vars.REGISTRY }}/${{ vars.IMAGE_NAME }}:${{ steps.get-warp-client-version.outputs.WARP_VERSION }}-${{ steps.get-gost-version.outputs.GOST_VERSION }}
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM ubuntu:22.04

ARG GOST_VERSION

# install dependencies
RUN apt-get update && \
apt-get upgrade -y && \
Expand All @@ -10,9 +12,9 @@ RUN apt-get update && \
apt-get install -y cloudflare-warp && \
apt-get clean && \
apt-get autoremove -y && \
curl -LO https://github.com/ginuerzh/gost/releases/download/v2.11.5/gost-linux-amd64-2.11.5.gz && \
gunzip gost-linux-amd64-2.11.5.gz && \
mv gost-linux-amd64-2.11.5 /usr/bin/gost && \
curl -LO https://github.com/ginuerzh/gost/releases/download/v${GOST_VERSION}/gost-linux-amd64-${GOST_VERSION}.gz && \
gunzip gost-linux-amd64-${GOST_VERSION}.gz && \
mv gost-linux-amd64-${GOST_VERSION} /usr/bin/gost && \
chmod +x /usr/bin/gost

# Accept Cloudflare WARP TOS
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Run official [Cloudflare WARP](https://1.1.1.1/) client in Docker.

> [!NOTE]
> Cannot guarantee that the [GOST](https://github.com/ginuerzh/gost) and WARP client contained in the image are the latest versions. If necessary, please [build your own image](#build).
## Usage

### Start the container
Expand Down Expand Up @@ -65,6 +68,31 @@ HEALTHCHECK --interval=15s --timeout=5s --start-period=30s --retries=3 \

If you don't want the container to restart automatically, you can remove `restart: always` from the `docker-compose.yml`. You can also modify the parameters of the health check through the `docker-compose.yml`.

### Use other versions

The tag of docker image is in the format of `{WARP_VERSION}-{GOST_VERSION}`, for example, `2023.10.120-2.11.5` means that the WARP client version is `2023.10.120` and the GOST version is `2.11.5`. If you want to use other versions, you can specify the tag in the `docker-compose.yml`.

You can also use the `latest` tag to use the latest version of the image.

> [!NOTE]
> Not all version combinations are available. Do check [the list of tags in Docker Hub](https://hub.docker.com/r/caomingjun/warp/tags) before you use one. If the version you want is not available, you can [build your own image](#build).
## Build

You can use Github Actions to build the image yourself.

1. Fork this repository.
2. Create necessary variables and secrets in the repository settings:
1. variable `REGISTRY`: for example, `docker.io` (Docker Hub)
2. variable `IMAGE_NAME`: for example, `caomingjun/warp`
3. variable `DOCKER_USERNAME`: for example, `caomingjun`
4. secret `DOCKER_PASSWORD`: generate a token in Docker Hub and fill in the token
3. Manually trigger the workflow `Build and push image` in the Actions tab.

This will build the image with the latest version of WARP client and GOST and push it to the specified registry. You can also specify the version of GOST by giving input to the workflow. Building image with custom WARP client version is not supported yet.

If you want to build the image locally, you can use [`.github/workflows/build-publish.yml`](.github/workflows/build-publish.yml) as a reference.

## Further reading

Read in my [blog post](https://blog.caomingjun.com/run-cloudflare-warp-in-docker/en/#How-it-works).

0 comments on commit 7beff19

Please sign in to comment.