diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..dc66cbb --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,81 @@ +name: Publish Docker Image + +on: + workflow_dispatch: + push: + branches: + - "main" + release: + types: [prereleased,released] + + +jobs: + + + publish-docker-image: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Prepare Tag + # Borrowed from daeuniverse/dae + id: prep + env: + REF: ${{ github.ref }} + run: | + if [[ "$REF" == "refs/tags/v"* ]]; then + tag=$(git describe --tags $(git rev-list --tags --max-count=1)) + tag=${tag:1} + else + tag=$(git log -1 --format="%cd" --date=short | sed s/-//g) + fi + echo "IMAGE=daeuniverse/dae-wing" >> $GITHUB_OUTPUT + echo "TAG=$tag" >> $GITHUB_OUTPUT + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + id: buildx + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to ghrc.io + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to quay.io + uses: docker/login-action@v3 + with: + registry: quay.io + username: ${{ github.repository_owner }} + password: ${{ secrets.QUAY_PASS }} + + - name: Build image + uses: docker/build-push-action@v5 + with: + context: . + build-args: VERSION=${{ steps.prep.outputs.TAG }} + builder: ${{ steps.buildx.outputs.name }} + platforms: linux/386,linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: | + ${{ github.repository }}:latest + ${{ github.repository }}:${{ steps.prep.outputs.TAG }} + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:${{ steps.prep.outputs.TAG }} + quay.io/${{ github.repository }}:latest + quay.io/${{ github.repository }}:${{ steps.prep.outputs.TAG }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fa8ab70 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# wing/Dockerfile +FROM golang:1.21-bookworm as builder + +WORKDIR /build + +RUN apt-get update +RUN apt-get install -y git make llvm-15 clang-15 + +ENV CGO_ENABLED=0 +ENV CLANG=clang-15 +ARG VERSION=self-build + +COPY . . + +RUN make APPNAME=dae-wing VERSION=$VERSION + +FROM alpine + +WORKDIR /etc/dae-wing + +RUN mkdir -p /usr/local/share/dae-wing +RUN wget -O /usr/local/share/dae-wing/geoip.dat https://github.com/v2rayA/dist-v2ray-rules-dat/raw/master/geoip.dat +RUN wget -O /usr/local/share/dae-wing/geosite.dat https://github.com/v2rayA/dist-v2ray-rules-dat/raw/master/geosite.dat +COPY --from=builder /build/dae-wing /usr/local/bin + +EXPOSE 2023 + +CMD ["dae-wing"] +ENTRYPOINT ["dae-wing", "run", "-c", "."] diff --git a/README.md b/README.md index bb40c8b..0a5b524 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,23 @@ lastcommit

-## Run +## Prerequisites + +[Git](https://git-scm.com), [Docker](https://www.docker.com), [Golang](https://go.dev), [GNU GCC](https://gcc.gnu.org) + +## Fetch the source code + +> Clone the repository with git submodules (dae-core) using git + +```shell +git clone https://github.com/daeuniverse/dae-wing +cd dae-wing + +# Initialize git submodules +git submodule update --init --recursive +``` + +## Run Locally To run the api only: @@ -25,6 +41,34 @@ go run -exec sudo . run # go build -o dae-wing && sudo ./dae-wing run -c ./ --api-only ``` +## Run with Docker + +> This feature is implemented for container orchestration with the dashboards that call this API, which also facilitates testing and development. + +Prebuilt image is available at `ghcr.io`. To pull this prebuilt image, you can replace image name into `ghcr.io/daeuniverse/dae-wing`. + +To build container from source: + +```bash +# use docker compose +sudo docker compose up -d + +# Or you can build then run with CLI +# build image +sudo docker build -t dae-wing . + +# run container +sudo docker run -d \ + --privileged \ + --network=host \ + --pid=host \ + --restart=always \ + -v /sys:/sys \ + -v /etc/dae-wing:/etc/dae-wing \ + --name=dae-wing \ + dae-wing +``` + ## API API is powered by [GraphQL](https://graphql.org/). UI developers can export schema and write queries and mutations easily. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..09b913f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3' + +services: + dae-wing: + privileged: true + network_mode: host + pid: host + build: . + container_name: dae-wing + volumes: + - /sys:/sys + - /etc/dae-wing:/etc/dae-wing