From e5fb0598dbb059dd5e52775a2a74aa540d01eb19 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Wed, 27 Jan 2021 23:54:06 +0800 Subject: [PATCH] workflow: add docker build and push job --- .github/workflows/docker.yml | 45 ++++++++++++++++++++++++++++++++++++ Dockerfile | 15 ++++-------- Dockerfile-alpine | 14 ----------- Dockerfile.alpine | 11 +++++++++ scripts/cross-build.sh | 3 +++ 5 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/docker.yml delete mode 100644 Dockerfile-alpine create mode 100644 Dockerfile.alpine diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..0cb3b7e --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,45 @@ +name: docker + +on: + push: + branches: master + +jobs: + docker: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Install packages + run: | + sudo apt-get update + sudo apt-get install -y autoconf automake build-essential cmake curl file libtool + - name: Cross build amd64/arm64 binary + run: | + for arch in amd64 arm64; do + env BUILD_TARGET=$arch ./scripts/cross-build.sh + cp build/ttyd ttyd.$arch + done + - uses: docker/setup-qemu-action@v1 + - uses: docker/setup-buildx-action@v1 + - uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USER }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - name: build/push docker image + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: | + tsl0922/ttyd:latest + - name: build/push docker image (alpine) + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile.alpine + platforms: linux/amd64,linux/arm64 + push: true + tags: | + tsl0922/ttyd:alpine \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 6197f7a..9f90cc7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,11 @@ -FROM ubuntu:18.04 -RUN apt-get update && apt-get install -y autoconf automake curl cmake git libtool make \ - && git clone --depth=1 https://github.com/tsl0922/ttyd.git /ttyd \ - && cd /ttyd && env BUILD_TARGET=x86_64 ./scripts/cross-build.sh +FROM ubuntu:20.04 -FROM ubuntu:18.04 -COPY --from=0 /ttyd/build/ttyd /usr/bin/ttyd - -ADD https://github.com/krallin/tini/releases/download/v0.18.0/tini /sbin/tini -RUN chmod +x /sbin/tini +ARG TARGETARCH +COPY ./ttyd.${TARGETARCH} /usr/bin/ttyd +RUN apt-get update && apt-get install -y --no-install-recommends tini && rm -rf /var/lib/apt/lists/* EXPOSE 7681 WORKDIR /root -ENTRYPOINT ["/sbin/tini", "--"] +ENTRYPOINT ["/usr/bin/tini", "--"] CMD ["ttyd", "bash"] diff --git a/Dockerfile-alpine b/Dockerfile-alpine deleted file mode 100644 index 9c31af0..0000000 --- a/Dockerfile-alpine +++ /dev/null @@ -1,14 +0,0 @@ -FROM ubuntu:18.04 -RUN apt-get update && apt-get install -y autoconf automake curl cmake git libtool make \ - && git clone --depth=1 https://github.com/tsl0922/ttyd.git /ttyd \ - && cd /ttyd && env BUILD_TARGET=x86_64 ./scripts/cross-build.sh - -FROM alpine -COPY --from=0 /ttyd/build/ttyd /usr/bin/ttyd -RUN apk add --no-cache bash tini - -EXPOSE 7681 -WORKDIR /root - -ENTRYPOINT ["/sbin/tini", "--"] -CMD ["ttyd", "bash"] diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 0000000..9347dfe --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,11 @@ +FROM alpine + +ARG TARGETARCH +COPY ./ttyd.${TARGETARCH} /usr/bin/ttyd +RUN apk add --no-cache bash tini + +EXPOSE 7681 +WORKDIR /root + +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["ttyd", "bash"] diff --git a/scripts/cross-build.sh b/scripts/cross-build.sh index 848aef5..185d838 100755 --- a/scripts/cross-build.sh +++ b/scripts/cross-build.sh @@ -153,6 +153,9 @@ build() { build_ttyd } +[ "${BUILD_TARGET}" = "amd64" ] && BUILD_TARGET="x86_64" +[ "${BUILD_TARGET}" = "arm64" ] && BUILD_TARGET="aarch64" + case ${BUILD_TARGET} in i686|x86_64|aarch64|mips|mipsel|mips64|mips64el) build "${BUILD_TARGET}-linux-musl" "${BUILD_TARGET}" -- 2.43.4