build-and-push-image.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. -
  17. name: Set up Go 1.x
  18. uses: actions/setup-go@v2
  19. with:
  20. go-version: 1.15
  21. -
  22. run: go version
  23. -
  24. name: Check out code into the Go module directory
  25. uses: actions/checkout@v2
  26. -
  27. name: Build
  28. run: make build
  29. -
  30. name: Archive artifacts for frpc
  31. uses: actions/upload-artifact@v1
  32. with:
  33. name: frpc
  34. path: bin/frpc
  35. -
  36. name: Archive artifacts for frps
  37. uses: actions/upload-artifact@v1
  38. with:
  39. name: frps
  40. path: bin/frps
  41. image:
  42. name: Build Image from Dockerfile and binaries
  43. runs-on: ubuntu-latest
  44. needs: binary
  45. steps:
  46. # environment
  47. -
  48. name: Checkout
  49. uses: actions/checkout@v2
  50. with:
  51. fetch-depth: '0'
  52. -
  53. name: Set up QEMU
  54. uses: docker/setup-qemu-action@v1
  55. -
  56. name: Set up Docker Buildx
  57. uses: docker/setup-buildx-action@v1
  58. # download binaries of frpc and frps
  59. -
  60. name: Download binary of frpc
  61. uses: actions/download-artifact@v2
  62. with:
  63. name: frpc
  64. path: bin/frpc
  65. -
  66. name: Download binary of frps
  67. uses: actions/download-artifact@v2
  68. with:
  69. name: frps
  70. path: bin/frps
  71. # get image tag name
  72. -
  73. name: Get Image Tag Name
  74. run: |
  75. if [ x${{ github.event.inputs.tag }} == x"" ]; then
  76. echo ::set-env name=TAG_NAME::${GITHUB_REF#refs/*/}
  77. else
  78. echo ::set-env name=TAG_NAME::${{ github.event.inputs.tag }}
  79. fi
  80. # prepare image tags
  81. -
  82. name: Prepare Image Tags
  83. run: |
  84. echo ::set-env name=DOCKERFILE_FRPC_PATH::dockerfiles/Dockerfile-for-frpc
  85. echo ::set-env name=DOCKERFILE_FRPS_PATH::dockerfiles/Dockerfile-for-frps
  86. echo ::set-env name=TAG_FRPC::fatedier/frpc:$TAG_NAME
  87. echo ::set-env name=TAG_FRPS::fatedier/frps:$TAG_NAME
  88. echo ::set-env name=TAG_FRPC_GPR::ghcr.io/fatedier/frpc:$TAG_NAME
  89. echo ::set-env name=TAG_FRPS_GPR::ghcr.io/fatedier/frps:$TAG_NAME
  90. # build images
  91. -
  92. name: Build Images
  93. run: |
  94. # for Docker hub
  95. docker build --file $DOCKERFILE_FRPC_PATH --tag $TAG_FRPC .
  96. docker build --file $DOCKERFILE_FRPS_PATH --tag $TAG_FRPS .
  97. # for GPR
  98. docker build --file $DOCKERFILE_FRPC_PATH --tag $TAG_FRPC_GPR .
  99. docker build --file $DOCKERFILE_FRPS_PATH --tag $TAG_FRPS_GPR .
  100. # push to dockerhub
  101. -
  102. name: Publish to Dockerhub
  103. run: |
  104. echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
  105. docker push $TAG_FRPC
  106. docker push $TAG_FRPS
  107. # push to gpr
  108. -
  109. name: Publish to GPR
  110. run: |
  111. echo ${{ secrets.GPR_TOKEN }} | docker login ghcr.io --username ${{ github.repository_owner }} --password-stdin
  112. docker push $TAG_FRPC_GPR
  113. docker push $TAG_FRPS_GPR