Skip to content

Commit

Permalink
ci(docker): rework workflow (3rd time) (#289)
Browse files Browse the repository at this point in the history
Signed-off-by: hero-intelligent <[email protected]>
Co-authored-by: kev <[email protected]>
  • Loading branch information
hero-intelligent and piyoki authored Oct 20, 2023
1 parent 1744638 commit 79dd55a
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 30 deletions.
129 changes: 108 additions & 21 deletions .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,148 @@ name: Publish Docker Image

on:
workflow_dispatch:
push:
branches:
- "main"
release:
types: [prereleased]
types: [prereleased,released]


jobs:

build-web:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- uses: pnpm/action-setup@v2
with:
version: latest

- uses: actions/setup-node@v3
with:
cache: pnpm
node-version: latest

- name: Build
run: |
pnpm install
pnpm build
- name: Upload artifact - web
uses: actions/upload-artifact@v3
with:
name: web
path: dist


publish-docker-image:
runs-on: ubuntu-latest
needs:
- build-web

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Download artifact - web
uses: actions/download-artifact@v3
with:
name: web
path: dist/

- name: Prepare Tag
# Borrowed from daeuniverse/dae
id: prep
env:
REF: ${{ github.ref }}
run: |
DIR="$(pwd)/dist/"
if [ -d "$DIR" ]; then
### Take action if $DIR exists ###
echo "Installing config files in ${DIR}..."
else
### Control will jump here if $DIR does NOT exists ###
echo "Error: ${DIR} not found. Can not continue."
exit 1
fi
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/daed" >> $GITHUB_OUTPUT
echo "TAG=$tag" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
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@v2
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ github.repository_owner }}
password: ${{ secrets.QUAY_PASS }}

- name: Build quay.io image
uses: docker/build-push-action@v4
- name: Build image
if: github.event_name == 'release'
uses: docker/build-push-action@v5
with:
context: .
build-args: DAED_VERSION=${{ steps.prep.outputs.TAG }}
builder: ${{ steps.buildx.outputs.name }}
file: Dockerfile
platforms: linux/amd64
file: publish.Dockerfile
target: prod
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

- name: Login to ghrc.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build ghcr.io image
uses: docker/build-push-action@v4
- name: Test Build
if: github.event_name != 'release'
uses: docker/build-push-action@v5
with:
context: .
build-args: DAED_VERSION=${{ steps.prep.outputs.TAG }}
builder: ${{ steps.buildx.outputs.name }}
file: Dockerfile
platforms: linux/amd64
file: publish.Dockerfile
target: prod
platforms: linux/386,linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
${{ github.repository }}:test
${{ github.repository }}:${{ steps.prep.outputs.TAG }}-test
ghcr.io/${{ github.repository }}:test
ghcr.io/${{ github.repository }}:${{ steps.prep.outputs.TAG }}-test
quay.io/${{ github.repository }}:test
quay.io/${{ github.repository }}:${{ steps.prep.outputs.TAG }}-test
cache-from: type=gha
cache-to: type=gha,mode=max
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ RUN \
# build bundle process
ENV CGO_ENABLED=0
ENV CLANG=clang-15
ARG DAED_VERSION=self-build

WORKDIR /build
COPY --from=build-web /build/dist /build/web
COPY --from=build-web /build/wing /build/wing

WORKDIR /build/wing

COPY --from=build-web /build/dist web
COPY --from=build-web /build/wing wing
RUN make APPNAME=daed VERSION=$DAED_VERSION OUTPUT=daed WEB_DIST=/build/web/ bundle

RUN cd wing && make APPNAME=daed OUTPUT=daed WEB_DIST=/build/web/ bundle



Expand Down
28 changes: 23 additions & 5 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# Quick Start Guide

> **Note**: `daed` (UI component) is bundled with [dae-wing](https://github.com/daeuniverse/dae-wing) (backend API server) and [dae](https://github.com/daeuniverse/dae) (core).
> **Note**
> `daed` (UI component) is bundled with [dae-wing](https://github.com/daeuniverse/dae-wing) (backend API server) and [dae](https://github.com/daeuniverse/dae) (core).
## How to run

> **Note**
> - NEVER LET YOUR COMPUTER SLEEP OR HIBIRNATE WHILE PROXY IS STILL ON!
> - NEVER SWITCH NETWORK WHILE PROXY IS STILL ON!
> - TURN IT OFF BEFORE YOU MOVE OR LEAVE YOUR COMPUTER!
> - OR YOU WILL HAVE POSSIBILITY TO NEED A REBOOT TO RECOVER YOUR NETWORK CONNECTIVITY!
### Download pre-compiled binaries

Releases are available in <https://github.com/daeuniverse/daed/releases>

> **Note**: If you would like to get a taste of new features, there are `PR Builds` available. Most of the time, newly proposed changes will be included in `PRs` and will be exported as cross-platform executable binaries in builds (GitHub Action Workflow Build). Noted that newly introduced features are sometimes buggy, do it at your own risk. However, we still highly encourage you to check out our latest builds as it may help us further analyze features stability and resolve potential bugs accordingly.
> **Note**
> If you would like to get a taste of new features, there are `PR Builds` available. Most of the time, newly proposed changes will be included in `PRs` and will be exported as cross-platform executable binaries in builds (GitHub Action Workflow Build). Noted that newly introduced features are sometimes buggy, do it at your own risk. However, we still highly encourage you to check out our latest builds as it may help us further analyze features stability and resolve potential bugs accordingly.
PR-builds are available in <https://github.com/daeuniverse/daed/actions/workflows/pr-build.yml>

Expand Down Expand Up @@ -109,7 +117,9 @@ sudo pacman -S daed-git
``````
### Docker (Experimental)

Pre-built Docker images are available in `ghcr.io/daeuniverse/daed`. The command below pulls and runs the latest image
Pre-built Docker images are available in `ghcr.io/daeuniverse/daed`, `quay.io/daeuniverse/daed` and `daeuniverse/daed`.

#### Take `ghcr.io` for example, the command below pulls and runs the latest image

```shell
sudo docker run -d \
Expand All @@ -123,8 +133,7 @@ sudo docker run -d \
ghcr.io/daeuniverse/daed:latest
```

> **Note**
> You may also build from source:
#### You may also build from source:

```shell
# clone the repository
Expand All @@ -145,6 +154,15 @@ sudo docker run -d \
daed
```


> **NOTE**
> - Docker currently supports only i386(x86-32), amd64(x86-64), armv7 and arm64(armv8). (Alpha)
> - Only amd64 is tested working as expected, but not fully tested yet. (Beta)
> - For self build from source, only amd64 and arm64 will run.
> - Please refer to https://github.com/daeuniverse/daed/discussions/291 and relevant PRs and Issues for details
> - Volunteers are welcomed.

## Access Panel

If everything goes well, open your browser and navigate to `http://localhost:2023`
Expand Down
38 changes: 38 additions & 0 deletions publish.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# ATTENTION This part below is for publishing purpose only

ARG DAED_VERSION

FROM golang:1.21-bookworm as build

RUN \
apt-get update; apt-get install -y git make llvm-15 clang-15; \
apt-get clean autoclean && apt-get autoremove -y && rm -rf /var/lib/{apt,dpkg,cache,log}/

# build bundle process
ENV CGO_ENABLED=0
ENV CLANG=clang-15
ARG DAED_VERSION

WORKDIR /build

COPY ./dist/ ./web/
COPY ./wing/ ./wing/

WORKDIR /build/wing

RUN make APPNAME=daed VERSION=$DAED_VERSION OUTPUT=daed WEB_DIST=/build/web/ bundle


FROM alpine as prod

LABEL org.opencontainers.image.source=https://github.com/daeuniverse/daed

RUN mkdir -p /usr/local/share/daed/
RUN mkdir -p /etc/daed/
RUN wget -O /usr/local/share/daed/geoip.dat https://github.com/v2rayA/dist-v2ray-rules-dat/raw/master/geoip.dat; \
wget -O /usr/local/share/daed/geosite.dat https://github.com/v2rayA/dist-v2ray-rules-dat/raw/master/geosite.dat
COPY --from=build /build/wing/daed /usr/local/bin

EXPOSE 2023

CMD ["daed", "run", "-c", "/etc/daed"]

0 comments on commit 79dd55a

Please sign in to comment.