summaryrefslogtreecommitdiffstats
path: root/.github/workflows/docker.yml
blob: de6ce6531ca7eea97f890fccac2a46e718e1aeea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: docker

on:
  push:
    branches: main
    tags: "*"

jobs:
  build:
    runs-on: ubuntu-20.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 multi-arch binary
        run: |
          mkdir dist
          for arch in amd64 armv7 arm64 s390x; do
            env BUILD_TARGET=$arch ./scripts/cross-build.sh
            [ "$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
      - uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_HUB_USER }}
          password: ${{ secrets.DOCKER_HUB_TOKEN }}
      - name: Determine docker tags
        id: docker_tag
        run: |
          case $GITHUB_REF in
            refs/tags/*)
              TAG_NAME=${GITHUB_REF#refs/tags/}
              echo ::set-output name=DOCKER_TAG::tsl0922/ttyd:${TAG_NAME}
              echo ::set-output name=ALPINE_TAG::tsl0922/ttyd:${TAG_NAME}-alpine
              ;;
            *)
              echo ::set-output name=DOCKER_TAG::tsl0922/ttyd:latest
              echo ::set-output name=ALPINE_TAG::tsl0922/ttyd:alpine
          esac
      - name: build/push docker image
        uses: docker/build-push-action@v2
        with:
          context: .
          file: ./Dockerfile
          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/arm/v7,linux/arm64,linux/s390x
          push: true
          tags: ${{ steps.docker_tag.outputs.ALPINE_TAG }}