Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docker images #3737

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.circleci/
.git/
.github/
.idea/
.vscode/
conf/
doc/
hack/
test/
web/
*.md
*.sh
.dockerignore
.gitignore
.golangci.yml
.goreleaser.yml
Dockerfile
LICENSE
Makefile.cross-compiles
26 changes: 10 additions & 16 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM golang:1.21 AS builder

WORKDIR /building
COPY . .

ARG APP
RUN make ${APP}

FROM alpine:3.18 AS runtime
fatedier marked this conversation as resolved.
Show resolved Hide resolved

ARG APP
RUN addgroup -g 1000 -S ${APP} && adduser -u 1000 -S ${APP} -G ${APP} --home /app \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that frp is often used to listen on port 80, will not using the root user have any impact? On the other hand, what problems may arise from using the root user?

Copy link
Contributor Author

@reneleonhardt reneleonhardt Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using root opens the attack surface to a whole lot more security bug possibilities.
The privileged port problem was solved 3 years ago:
https://stackoverflow.com/questions/66431299/i-can-bind-to-port-80-as-a-non-root-user-in-a-docker-container-why-whats-goin
Can you try both new images to verify the expected functionality?

It would be optimal if the Docker build would automatically verify the expected functionality... 😉

&& echo -e "#!/bin/sh\nexec /usr/local/bin/${APP} \$@" > /app/entrypoint.sh \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this script? What are the differences compared to the previous execution method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for introducing this script was the unification of the 2 Dockerfiles into 1.
It's not allowed to use ARG/ENV variables inside ENTRYPOINT, your binaries have different names, it's best practice to create a minimal exec script in this case.
I will improve it a bit to make hadolint happy 😄

&& chmod +x /app/entrypoint.sh

FROM alpine:3.18

ARG APP
ARG TITLE
LABEL org.opencontainers.image.authors="fatedier <[email protected]>"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these labels? What benefits will it bring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best practice, a docker image tag is a also only a "label", those labels make it easier for your users what's inside this image.
The specific app version would be good too, but a bit harder to integrate in this case.
https://snyk.io/blog/how-and-when-to-use-docker-labels-oci-container-annotations/

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not prefer to add these redundant information.

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"]
12 changes: 0 additions & 12 deletions dockerfiles/Dockerfile-for-frpc

This file was deleted.

12 changes: 0 additions & 12 deletions dockerfiles/Dockerfile-for-frps

This file was deleted.