diff --git a/.dockerignore b/.dockerignore index 4fe7821e355..acee471d8f5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,7 +5,6 @@ .vscode/ conf/ doc/ -dockerfiles/ hack/ test/ web/ @@ -15,5 +14,6 @@ web/ .gitignore .golangci.yml .goreleaser.yml +Dockerfile LICENSE Makefile.cross-compiles diff --git a/.github/workflows/build-and-push-image.yml b/.github/workflows/build-and-push-image.yml index 9607ba1823a..c816a354cbf 100644 --- a/.github/workflows/build-and-push-image.yml +++ b/.github/workflows/build-and-push-image.yml @@ -50,34 +50,28 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GPR_TOKEN }} - # 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 - - name: Build and push frpc uses: docker/build-push-action@v4 with: context: . - file: ./dockerfiles/Dockerfile-for-frpc platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x push: true tags: | - ${{ env.TAG_FRPC }} - ${{ env.TAG_FRPC_GPR }} + fatedier/frpc:${{ env.TAG_NAME }} + ghcr.io/fatedier/frpc:${{ env.TAG_NAME }} + build-args: | + APP=frpc + TITLE=frpc (client) - name: Build and push frps uses: docker/build-push-action@v4 with: context: . - file: ./dockerfiles/Dockerfile-for-frps platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x push: true tags: | - ${{ env.TAG_FRPS }} - ${{ env.TAG_FRPS_GPR }} + fatedier/frps:${{ env.TAG_NAME }} + ghcr.io/fatedier/frps:${{ env.TAG_NAME }} + build-args: | + APP=frps + TITLE=frps (server) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..1e12f83fd66 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM golang:1.21 AS builder + +WORKDIR /building +COPY . . + +ARG APP +RUN make ${APP} + +FROM alpine:3.18 AS runtime + +ARG APP +RUN addgroup -g 1000 -S ${APP} && adduser -u 1000 -S ${APP} -G ${APP} --home /app \ + && echo -e "#!/bin/sh\nexec /usr/local/bin/${APP} \$@" > /app/entrypoint.sh \ + && chmod +x /app/entrypoint.sh + +FROM alpine:3.18 + +ARG APP +ARG TITLE +LABEL org.opencontainers.image.authors="fatedier " +LABEL org.opencontainers.image.base.name="docker.io/library/alpine:3.18" +LABEL org.opencontainers.image.description="A fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet." +LABEL org.opencontainers.image.licenses="Apache-2.0" +LABEL org.opencontainers.image.source="https://github.com/fatedier/frp" +LABEL org.opencontainers.image.title="${TITLE}" + +WORKDIR / +COPY --from=runtime /etc/passwd /etc/group /etc/ +COPY --from=runtime --chown=1000:1000 /app/ /app/ +COPY --from=builder --chown=1000:1000 /building/bin/${APP} /usr/local/bin/ + +USER ${APP} + +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/dockerfiles/Dockerfile-for-frpc b/dockerfiles/Dockerfile-for-frpc deleted file mode 100644 index 4170e76ff4e..00000000000 --- a/dockerfiles/Dockerfile-for-frpc +++ /dev/null @@ -1,24 +0,0 @@ -FROM golang:1.21 AS builder - -WORKDIR /building -COPY . . - -RUN groupadd -g 1000 frpc && useradd -u 1000 -g frpc frpc \ - && make frpc - -FROM alpine:3.18 - -LABEL org.opencontainers.image.authors="fatedier " -LABEL org.opencontainers.image.base.name="docker.io/library/alpine:3.18" -LABEL org.opencontainers.image.description="A fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet." -LABEL org.opencontainers.image.licenses="Apache-2.0" -LABEL org.opencontainers.image.source="https://github.com/fatedier/frp" -LABEL org.opencontainers.image.title="frpc (client)" - -WORKDIR / -COPY --from=builder /etc/passwd /etc/ -COPY --from=builder --chown=1000:1000 /building/bin/frpc /usr/local/bin/ - -USER frpc - -ENTRYPOINT ["/usr/local/bin/frpc"] diff --git a/dockerfiles/Dockerfile-for-frps b/dockerfiles/Dockerfile-for-frps deleted file mode 100644 index 47f72aa967f..00000000000 --- a/dockerfiles/Dockerfile-for-frps +++ /dev/null @@ -1,24 +0,0 @@ -FROM golang:1.21 AS builder - -WORKDIR /building -COPY . . - -RUN groupadd -g 1000 frps && useradd -u 1000 -g frps frps \ - && make frps - -FROM alpine:3.18 - -LABEL org.opencontainers.image.authors="fatedier " -LABEL org.opencontainers.image.base.name="docker.io/library/alpine:3.18" -LABEL org.opencontainers.image.description="A fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet." -LABEL org.opencontainers.image.licenses="Apache-2.0" -LABEL org.opencontainers.image.source="https://github.com/fatedier/frp" -LABEL org.opencontainers.image.title="frps (server)" - -WORKDIR / -COPY --from=builder /etc/passwd /etc/ -COPY --from=builder --chown=1000:1000 /building/bin/frps /usr/local/bin/ - -USER frps - -ENTRYPOINT ["/usr/local/bin/frps"]