feat: Unify docker build

This commit is contained in:
Rene Leonhardt 2023-10-31 10:07:58 +01:00
parent b41b8ae13a
commit 54218d0cab
No known key found for this signature in database
GPG Key ID: F3648D7E366BF1B4
5 changed files with 45 additions and 65 deletions

View File

@ -5,7 +5,6 @@
.vscode/ .vscode/
conf/ conf/
doc/ doc/
dockerfiles/
hack/ hack/
test/ test/
web/ web/
@ -15,5 +14,6 @@ web/
.gitignore .gitignore
.golangci.yml .golangci.yml
.goreleaser.yml .goreleaser.yml
Dockerfile
LICENSE LICENSE
Makefile.cross-compiles Makefile.cross-compiles

View File

@ -50,34 +50,28 @@ jobs:
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
password: ${{ secrets.GPR_TOKEN }} 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 - name: Build and push frpc
uses: docker/build-push-action@v4 uses: docker/build-push-action@v4
with: with:
context: . context: .
file: ./dockerfiles/Dockerfile-for-frpc
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x
push: true push: true
tags: | tags: |
${{ env.TAG_FRPC }} fatedier/frpc:${{ env.TAG_NAME }}
${{ env.TAG_FRPC_GPR }} ghcr.io/fatedier/frpc:${{ env.TAG_NAME }}
build-args: |
APP=frpc
TITLE=frpc (client)
- name: Build and push frps - name: Build and push frps
uses: docker/build-push-action@v4 uses: docker/build-push-action@v4
with: with:
context: . context: .
file: ./dockerfiles/Dockerfile-for-frps
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x
push: true push: true
tags: | tags: |
${{ env.TAG_FRPS }} fatedier/frps:${{ env.TAG_NAME }}
${{ env.TAG_FRPS_GPR }} ghcr.io/fatedier/frps:${{ env.TAG_NAME }}
build-args: |
APP=frps
TITLE=frps (server)

34
Dockerfile Normal file
View File

@ -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 <fatedier@gmail.com>"
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"]

View File

@ -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 <fatedier@gmail.com>"
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"]

View File

@ -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 <fatedier@gmail.com>"
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"]