build-and-push-image.yml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. name: Build Image and Publish to Dockerhub & GPR
  2. on:
  3. release:
  4. types: [ created ]
  5. workflow_dispatch:
  6. inputs:
  7. tag:
  8. description: 'Image tag'
  9. required: true
  10. default: 'test'
  11. jobs:
  12. binary:
  13. name: Build Golang project
  14. runs-on: ubuntu-latest
  15. steps:
  16. - name: Set up Go 1.x
  17. uses: actions/setup-go@v2
  18. with:
  19. go-version: 1.17
  20. - run: |
  21. # https://github.com/actions/setup-go/issues/107
  22. cp -f `which go` /usr/bin/go
  23. - run: go version
  24. - name: Check out code into the Go module directory
  25. uses: actions/checkout@v2
  26. - name: Build
  27. run: make build
  28. - name: Archive artifacts for frpc
  29. uses: actions/upload-artifact@v1
  30. with:
  31. name: frpc
  32. path: bin/frpc
  33. - name: Archive artifacts for frps
  34. uses: actions/upload-artifact@v1
  35. with:
  36. name: frps
  37. path: bin/frps
  38. image:
  39. name: Build Image from Dockerfile and binaries
  40. runs-on: ubuntu-latest
  41. needs: binary
  42. steps:
  43. # environment
  44. - name: Checkout
  45. uses: actions/checkout@v2
  46. with:
  47. fetch-depth: '0'
  48. - name: Set up QEMU
  49. uses: docker/setup-qemu-action@v1
  50. - name: Set up Docker Buildx
  51. uses: docker/setup-buildx-action@v1
  52. # download binaries of frpc and frps
  53. - name: Download binary of frpc
  54. uses: actions/download-artifact@v2
  55. with:
  56. name: frpc
  57. path: bin/frpc
  58. - name: Download binary of frps
  59. uses: actions/download-artifact@v2
  60. with:
  61. name: frps
  62. path: bin/frps
  63. # get image tag name
  64. - name: Get Image Tag Name
  65. run: |
  66. if [ x${{ github.event.inputs.tag }} == x"" ]; then
  67. echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
  68. else
  69. echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
  70. fi
  71. # prepare image tags
  72. - name: Prepare Image Tags
  73. run: |
  74. echo "DOCKERFILE_FRPC_PATH=dockerfiles/Dockerfile-for-frpc" >> $GITHUB_ENV
  75. echo "DOCKERFILE_FRPS_PATH=dockerfiles/Dockerfile-for-frps" >> $GITHUB_ENV
  76. echo "TAG_FRPC=fatedier/frpc:${{ env.TAG_NAME }}" >> $GITHUB_ENV
  77. echo "TAG_FRPS=fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV
  78. echo "TAG_FRPC_GPR=ghcr.io/fatedier/frpc:${{ env.TAG_NAME }}" >> $GITHUB_ENV
  79. echo "TAG_FRPS_GPR=ghcr.io/fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV
  80. # build images
  81. - name: Build Images
  82. run: |
  83. # for Docker hub
  84. docker build --file ${{ env.DOCKERFILE_FRPC_PATH }} --tag ${{ env.TAG_FRPC }} .
  85. docker build --file ${{ env.DOCKERFILE_FRPS_PATH }} --tag ${{ env.TAG_FRPS }} .
  86. # for GPR
  87. docker build --file ${{ env.DOCKERFILE_FRPC_PATH }} --tag ${{ env.TAG_FRPC_GPR }} .
  88. docker build --file ${{ env.DOCKERFILE_FRPS_PATH }} --tag ${{ env.TAG_FRPS_GPR }} .
  89. # push to dockerhub
  90. - name: Publish to Dockerhub
  91. run: |
  92. echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
  93. docker push ${{ env.TAG_FRPC }}
  94. docker push ${{ env.TAG_FRPS }}
  95. # push to gpr
  96. - name: Publish to GPR
  97. run: |
  98. echo ${{ secrets.GPR_TOKEN }} | docker login ghcr.io --username ${{ github.repository_owner }} --password-stdin
  99. docker push ${{ env.TAG_FRPC_GPR }}
  100. docker push ${{ env.TAG_FRPS_GPR }}