diff --git a/.github/workflows/build-and-push-image.yml b/.github/workflows/build-and-push-image.yml index d929e58b..df5f737c 100644 --- a/.github/workflows/build-and-push-image.yml +++ b/.github/workflows/build-and-push-image.yml @@ -1,4 +1,4 @@ -name: Build Image and Publish to Dockerhub & GPR +name: Build Docker Image on: release: @@ -9,109 +9,77 @@ on: description: 'Image tag' required: true default: 'test' + jobs: - binary: - name: Build Golang project + buildx: runs-on: ubuntu-latest steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - run: | - # https://github.com/actions/setup-go/issues/107 - cp -f `which go` /usr/bin/go - - - run: go version - - - name: Check out code into the Go module directory + - + name: Checkout 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 + - name: Get current date + id: date + run: echo "::set-output name=today::$(date +'%Y-%m-%d')" + - + name: Set up QEMU uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx + - + name: Set up Docker Buildx + id: 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 - - # get image tag name - - name: Get Image Tag Name + - + name: Available platforms + run: echo ${{ steps.buildx.outputs.platforms }} + - + name: Get Image Tag Name run: | if [ x${{ github.event.inputs.tag }} == x"" ]; then echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV else echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV fi - - # prepare image tags - - name: Prepare Image Tags - run: | - echo "DOCKERFILE_FRPC_PATH=dockerfiles/Dockerfile-for-frpc" >> $GITHUB_ENV - echo "DOCKERFILE_FRPS_PATH=dockerfiles/Dockerfile-for-frps" >> $GITHUB_ENV - echo "TAG_FRPC=fatedier/frpc:${{ env.TAG_NAME }}" >> $GITHUB_ENV - echo "TAG_FRPS=fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV - echo "TAG_FRPC_GPR=ghcr.io/fatedier/frpc:${{ env.TAG_NAME }}" >> $GITHUB_ENV - echo "TAG_FRPS_GPR=ghcr.io/fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV - - # build images - - name: Build Images - run: | - # for Docker hub - docker build --file ${{ env.DOCKERFILE_FRPC_PATH }} --tag ${{ env.TAG_FRPC }} . - docker build --file ${{ env.DOCKERFILE_FRPS_PATH }} --tag ${{ env.TAG_FRPS }} . - # for GPR - docker build --file ${{ env.DOCKERFILE_FRPC_PATH }} --tag ${{ env.TAG_FRPC_GPR }} . - docker build --file ${{ env.DOCKERFILE_FRPS_PATH }} --tag ${{ env.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 ${{ env.TAG_FRPC }} - docker push ${{ env.TAG_FRPS }} - - # push to gpr - - name: Publish to GPR - run: | - echo ${{ secrets.GPR_TOKEN }} | docker login ghcr.io --username ${{ github.repository_owner }} --password-stdin - docker push ${{ env.TAG_FRPC_GPR }} - docker push ${{ env.TAG_FRPS_GPR }} + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - + name: Login to the GPR + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Build and push frpc + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile.frpc + platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x + push: ${{ github.event_name != 'pull_request' }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache,mode=max + tags: | + fatedier/frpc:dev + fatedier/frpc:${{ env.TAG_NAME }} + fatedier/frpc:${{ steps.date.outputs.today }} + ghcr.io/fatedier/frpc:dev + ghcr.io/fatedier/frpc:${{ env.TAG_NAME }} + - + name: Build and push frps + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile.frps + platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x + push: ${{ github.event_name != 'pull_request' }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache,mode=max + tags: | + fatedier/frps:dev + fatedier/frps:${{ env.TAG_NAME }} + fatedier/frps:${{ steps.date.outputs.today }} + ghcr.io/fatedier/frps:dev + ghcr.io/fatedier/frps:${{ env.TAG_NAME }} \ No newline at end of file diff --git a/Dockerfile.frpc b/Dockerfile.frpc new file mode 100644 index 00000000..9236e206 --- /dev/null +++ b/Dockerfile.frpc @@ -0,0 +1,16 @@ +FROM golang:1.18-alpine3.15 AS building + +COPY . /building +WORKDIR /building + +RUN apk --no-cache add \ + git \ + && export GO111MODULE=on \ + && env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o ./bin/frpc ./cmd/frpc + +FROM alpine:3.15 +LABEL maintainer="i@muir.fun" + +COPY --from=building /building/bin/frpc /frpc + +CMD ["/frpc","-h"] \ No newline at end of file diff --git a/Dockerfile.frps b/Dockerfile.frps new file mode 100644 index 00000000..c0f3ef7f --- /dev/null +++ b/Dockerfile.frps @@ -0,0 +1,16 @@ +FROM golang:1.18-alpine3.15 AS building + +COPY . /building +WORKDIR /building + +RUN apk --no-cache add \ + git \ + && export GO111MODULE=on \ + && env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o ./bin/frps ./cmd/frps + +FROM alpine:3.15 +LABEL maintainer="i@muir.fun" + +COPY --from=building /building/bin/frps /frps + +CMD ["/frps","-h"] \ No newline at end of file diff --git a/dockerfiles/Dockerfile-for-frpc b/dockerfiles/Dockerfile-for-frpc deleted file mode 100644 index fce3d57a..00000000 --- a/dockerfiles/Dockerfile-for-frpc +++ /dev/null @@ -1,14 +0,0 @@ -FROM alpine:3 AS temp - -COPY bin/frpc /tmp - -RUN chmod -R 777 /tmp/frpc - - -FROM alpine:3 - -WORKDIR /app - -COPY --from=temp /tmp/frpc /usr/bin - -ENTRYPOINT ["/usr/bin/frpc"] diff --git a/dockerfiles/Dockerfile-for-frps b/dockerfiles/Dockerfile-for-frps deleted file mode 100644 index 3d65a9e4..00000000 --- a/dockerfiles/Dockerfile-for-frps +++ /dev/null @@ -1,14 +0,0 @@ -FROM alpine:3 AS temp - -COPY bin/frps /tmp - -RUN chmod -R 777 /tmp/frps - - -FROM alpine:3 - -WORKDIR /app - -COPY --from=temp /tmp/frps /usr/bin - -ENTRYPOINT ["/usr/bin/frps"]