workflow: add docker build and push job

This commit is contained in:
Shuanglei Tao
2021-01-27 23:54:06 +08:00
parent cea978eb93
commit e5fb0598db
5 changed files with 64 additions and 24 deletions

45
.github/workflows/docker.yml vendored Normal file
View File

@@ -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

View 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"]

View File

@@ -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"]

11
Dockerfile.alpine Normal file
View File

@@ -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"]

View File

@@ -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}"