build-and-push-image.yml 3.3 KB
Newer Older
1 2 3 4 5
name: Build Image and Publish to Dockerhub & GPR

on:
  release:
    types: [ created ]
F
fatedier 已提交
6 7 8 9 10 11
  workflow_dispatch:
    inputs:
      tag:
        description: 'Image tag'
        required: true
        default: 'test'
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 60 61 62 63 64 65 66 67 68 69 70 71 72
jobs:
  binary:
    name: Build Golang project
    runs-on: ubuntu-latest
    steps:
      -
        name: Set up Go 1.x
        uses: actions/setup-go@v2
        with:
          go-version: 1.15
      -
        run: go version
      -
        name: Check out code into the Go module directory
        uses: actions/checkout@v2
      -
        name: Build
        run: make build
      -
        name: Archive artifacts for frpc
        uses: actions/upload-artifact@v1
        with:
          name: frpc
          path: bin/frpc
      -
        name: Archive artifacts for frps
        uses: actions/upload-artifact@v1
        with:
          name: frps
          path: bin/frps

  image:
    name: Build Image from Dockerfile and binaries
    runs-on: ubuntu-latest
    needs: binary
    steps:
      # environment
      -
        name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: '0'
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      # download binaries of frpc and frps
      -
        name: Download binary of frpc
        uses: actions/download-artifact@v2
        with:
          name: frpc
          path: bin/frpc
      -
        name: Download binary of frps
        uses: actions/download-artifact@v2
        with:
          name: frps
          path: bin/frps
F
fatedier 已提交
73
      # get image tag name
74
      -
F
fatedier 已提交
75
        name: Get Image Tag Name
76
        run: |
F
typo  
fatedier 已提交
77
          if [ x${{ github.event.inputs.tag }} == x"" ]; then
F
fatedier 已提交
78 79 80 81
            echo ::set-env name=TAG_NAME::${GITHUB_REF#refs/*/}
          else
            echo ::set-env name=TAG_NAME::${{ github.event.inputs.tag }}
          fi
82 83 84 85 86 87
      # prepare image tags
      -
        name: Prepare Image Tags
        run: |
          echo ::set-env name=DOCKERFILE_FRPC_PATH::dockerfiles/Dockerfile-for-frpc
          echo ::set-env name=DOCKERFILE_FRPS_PATH::dockerfiles/Dockerfile-for-frps
F
fatedier 已提交
88 89 90 91
          echo ::set-env name=TAG_FRPC::fatedier/frpc:$TAG_NAME
          echo ::set-env name=TAG_FRPS::fatedier/frps:$TAG_NAME
          echo ::set-env name=TAG_FRPC_GPR::ghcr.io/fatedier/frpc:$TAG_NAME
          echo ::set-env name=TAG_FRPS_GPR::ghcr.io/fatedier/frps:$TAG_NAME
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
      # build images
      -
        name: Build Images
        run: |
          # for Docker hub
          docker build --file $DOCKERFILE_FRPC_PATH --tag $TAG_FRPC .
          docker build --file $DOCKERFILE_FRPS_PATH --tag $TAG_FRPS .
          # for GPR
          docker build --file $DOCKERFILE_FRPC_PATH --tag $TAG_FRPC_GPR .
          docker build --file $DOCKERFILE_FRPS_PATH --tag $TAG_FRPS_GPR .
      # push to dockerhub
      -
        name: Publish to Dockerhub
        run: |
          echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
          docker push $TAG_FRPC
F
fatedier 已提交
108
          docker push $TAG_FRPS
109 110 111 112 113 114 115
      # push to gpr
      -
        name: Publish to GPR
        run: |
          echo ${{ secrets.GPR_TOKEN }} | docker login ghcr.io --username ${{ github.repository_owner }} --password-stdin
          docker push $TAG_FRPC_GPR
          docker push $TAG_FRPS_GPR