Skip to content

Commit 44eb513

Browse files
authored
Update docker image build file (fatedier#2892)
* update docker image building
1 parent 6c65858 commit 44eb513

File tree

3 files changed

+59
-86
lines changed

3 files changed

+59
-86
lines changed

.github/workflows/build-and-push-image.yml

Lines changed: 37 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,9 @@ on:
1010
required: true
1111
default: 'test'
1212
jobs:
13-
binary:
14-
name: Build Golang project
15-
runs-on: ubuntu-latest
16-
steps:
17-
- name: Set up Go 1.x
18-
uses: actions/setup-go@v2
19-
with:
20-
go-version: 1.18
21-
22-
- run: |
23-
# https://github.com/actions/setup-go/issues/107
24-
cp -f `which go` /usr/bin/go
25-
26-
- run: go version
27-
28-
- name: Check out code into the Go module directory
29-
uses: actions/checkout@v2
30-
31-
- name: Build
32-
run: make build
33-
34-
- name: Archive artifacts for frpc
35-
uses: actions/upload-artifact@v1
36-
with:
37-
name: frpc
38-
path: bin/frpc
39-
40-
- name: Archive artifacts for frps
41-
uses: actions/upload-artifact@v1
42-
with:
43-
name: frps
44-
path: bin/frps
45-
4613
image:
4714
name: Build Image from Dockerfile and binaries
4815
runs-on: ubuntu-latest
49-
needs: binary
5016
steps:
5117
# environment
5218
- name: Checkout
@@ -60,19 +26,6 @@ jobs:
6026
- name: Set up Docker Buildx
6127
uses: docker/setup-buildx-action@v1
6228

63-
# download binaries of frpc and frps
64-
- name: Download binary of frpc
65-
uses: actions/download-artifact@v2
66-
with:
67-
name: frpc
68-
path: bin/frpc
69-
70-
- name: Download binary of frps
71-
uses: actions/download-artifact@v2
72-
with:
73-
name: frps
74-
path: bin/frps
75-
7629
# get image tag name
7730
- name: Get Image Tag Name
7831
run: |
@@ -81,6 +34,18 @@ jobs:
8134
else
8235
echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
8336
fi
37+
- name: Login to DockerHub
38+
uses: docker/login-action@v1
39+
with:
40+
username: ${{ secrets.DOCKERHUB_USERNAME }}
41+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
42+
43+
- name: Login to the GPR
44+
uses: docker/login-action@v1
45+
with:
46+
registry: ghcr.io
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
8449

8550
# prepare image tags
8651
- name: Prepare Image Tags
@@ -92,26 +57,28 @@ jobs:
9257
echo "TAG_FRPC_GPR=ghcr.io/fatedier/frpc:${{ env.TAG_NAME }}" >> $GITHUB_ENV
9358
echo "TAG_FRPS_GPR=ghcr.io/fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV
9459
95-
# build images
96-
- name: Build Images
97-
run: |
98-
# for Docker hub
99-
docker build --file ${{ env.DOCKERFILE_FRPC_PATH }} --tag ${{ env.TAG_FRPC }} .
100-
docker build --file ${{ env.DOCKERFILE_FRPS_PATH }} --tag ${{ env.TAG_FRPS }} .
101-
# for GPR
102-
docker build --file ${{ env.DOCKERFILE_FRPC_PATH }} --tag ${{ env.TAG_FRPC_GPR }} .
103-
docker build --file ${{ env.DOCKERFILE_FRPS_PATH }} --tag ${{ env.TAG_FRPS_GPR }} .
104-
105-
# push to dockerhub
106-
- name: Publish to Dockerhub
107-
run: |
108-
echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
109-
docker push ${{ env.TAG_FRPC }}
110-
docker push ${{ env.TAG_FRPS }}
111-
112-
# push to gpr
113-
- name: Publish to GPR
114-
run: |
115-
echo ${{ secrets.GPR_TOKEN }} | docker login ghcr.io --username ${{ github.repository_owner }} --password-stdin
116-
docker push ${{ env.TAG_FRPC_GPR }}
117-
docker push ${{ env.TAG_FRPS_GPR }}
60+
- name: Build and push frpc
61+
uses: docker/build-push-action@v2
62+
with:
63+
context: .
64+
file: ./dockerfiles/Dockerfile-for-frpc
65+
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
66+
push: ${{ github.event_name != 'pull_request' }}
67+
cache-from: type=local,src=/tmp/.buildx-cache
68+
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
69+
tags: |
70+
${{ env.TAG_FRPC }}
71+
${{ env.TAG_FRPC_GPR }}
72+
73+
- name: Build and push frps
74+
uses: docker/build-push-action@v2
75+
with:
76+
context: .
77+
file: ./dockerfiles/Dockerfile-for-frps
78+
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
79+
push: ${{ github.event_name != 'pull_request' }}
80+
cache-from: type=local,src=/tmp/.buildx-cache
81+
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
82+
tags: |
83+
${{ env.TAG_FRPS }}
84+
${{ env.TAG_FRPS_GPR }}

dockerfiles/Dockerfile-for-frpc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
FROM alpine:3 AS temp
1+
FROM golang:1.18-alpine3.15 AS building
22

3-
COPY bin/frpc /tmp
3+
COPY . /building
4+
WORKDIR /building
45

5-
RUN chmod -R 777 /tmp/frpc
6+
RUN apk --no-cache add \
7+
git \
8+
&& export GO111MODULE=on \
9+
&& env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o ./bin/frpc ./cmd/frpc
610

11+
FROM alpine:3.15
12+
LABEL maintainer="[email protected]"
713

8-
FROM alpine:3
9-
10-
WORKDIR /app
11-
12-
COPY --from=temp /tmp/frpc /usr/bin
14+
COPY --from=building /building/bin/frpc /usr/bin/frpc
1315

1416
ENTRYPOINT ["/usr/bin/frpc"]
17+
CMD ["-h"]

dockerfiles/Dockerfile-for-frps

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
FROM alpine:3 AS temp
1+
FROM golang:1.18-alpine3.15 AS building
22

3-
COPY bin/frps /tmp
3+
COPY . /building
4+
WORKDIR /building
45

5-
RUN chmod -R 777 /tmp/frps
6+
RUN apk --no-cache add \
7+
git \
8+
&& export GO111MODULE=on \
9+
&& env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o ./bin/frps ./cmd/frps
610

11+
FROM alpine:3.15
12+
LABEL maintainer="[email protected]"
713

8-
FROM alpine:3
9-
10-
WORKDIR /app
11-
12-
COPY --from=temp /tmp/frps /usr/bin
14+
COPY --from=building /building/bin/frps /usr/bin/frps
1315

1416
ENTRYPOINT ["/usr/bin/frps"]
17+
CMD ["-h"]

0 commit comments

Comments
 (0)