]> prime8.dev >> repos - ttyd.git/commitdiff
workflow: add docker build and push job
authorShuanglei Tao <tsl0922@gmail.com>
Wed, 27 Jan 2021 15:54:06 +0000 (23:54 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Wed, 27 Jan 2021 16:18:40 +0000 (00:18 +0800)
.github/workflows/docker.yml [new file with mode: 0644]
Dockerfile
Dockerfile-alpine [deleted file]
Dockerfile.alpine [new file with mode: 0644]
scripts/cross-build.sh

diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
new file mode 100644 (file)
index 0000000..0cb3b7e
--- /dev/null
@@ -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
index 6197f7a19c080fc7fa01cb5d64763a5e3a807eb9..9f90cc794f48caf257804236bd0bf6039613495e 100644 (file)
@@ -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 (file)
index 9c31af0..0000000
+++ /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 (file)
index 0000000..9347dfe
--- /dev/null
@@ -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"]
index 848aef5c00f37d2190ce7a3af6be672ecae6ece2..185d838052ad75c5723efda722ddbf96906c779a 100755 (executable)
@@ -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}"