Skip to content

Commit

Permalink
workflow: build docker image for armv7 and s390x
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Jan 28, 2021
1 parent e275bd6 commit 148d92f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y autoconf automake build-essential cmake curl file libtool
- name: Cross build amd64/arm64 binary
- name: Cross build multi-arch binary
run: |
for arch in amd64 arm64; do
mkdir dist
for arch in amd64 armv7 arm64 s390x; do
env BUILD_TARGET=$arch ./scripts/cross-build.sh
cp build/ttyd ttyd.$arch
[ "$arch" = "armv7" ] && arch="arm"
mkdir -p dist/$arch && cp build/ttyd dist/$arch/ttyd
done
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
Expand All @@ -44,14 +46,14 @@ jobs:
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/s390x
push: true
tags: ${{ steps.docker_tag.outputs.DOCKER_TAG }}
- name: build/push docker image (alpine)
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.alpine
platforms: linux/amd64,linux/arm64
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/s390x
push: true
tags: ${{ steps.docker_tag.outputs.ALPINE_TAG }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu:20.04

ARG TARGETARCH
COPY ./ttyd.${TARGETARCH} /usr/bin/ttyd
COPY ./dist/${TARGETARCH}/ttyd /usr/bin/ttyd
RUN apt-get update && apt-get install -y --no-install-recommends tini && rm -rf /var/lib/apt/lists/*

EXPOSE 7681
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine

ARG TARGETARCH
COPY ./ttyd.${TARGETARCH} /usr/bin/ttyd
COPY ./dist/${TARGETARCH}/ttyd /usr/bin/ttyd
RUN apk add --no-cache bash tini

EXPOSE 7681
Expand Down
14 changes: 10 additions & 4 deletions scripts/cross-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,25 @@ build() {
build_ttyd
}

[ "${BUILD_TARGET}" = "amd64" ] && BUILD_TARGET="x86_64"
[ "${BUILD_TARGET}" = "arm64" ] && BUILD_TARGET="aarch64"
case ${BUILD_TARGET} in
amd64) BUILD_TARGET="x86_64" ;;
arm64) BUILD_TARGET="aarch64" ;;
armv7) BUILD_TARGET="armv7l" ;;
esac

case ${BUILD_TARGET} in
i686|x86_64|aarch64|mips|mipsel|mips64|mips64el)
i686|x86_64|aarch64|mips|mipsel|mips64|mips64el|s390x)
build "${BUILD_TARGET}-linux-musl" "${BUILD_TARGET}"
;;
arm)
build arm-linux-musleabi "${BUILD_TARGET}"
build "${BUILD_TARGET}-linux-musleabi" "${BUILD_TARGET}"
;;
armhf)
build arm-linux-musleabihf "${BUILD_TARGET}"
;;
armv7l)
build armv7l-linux-musleabihf "${BUILD_TARGET}"
;;
*)
echo "unknown cross target: ${BUILD_TARGET}" && exit 1
esac

0 comments on commit 148d92f

Please sign in to comment.