update docker image building

This commit is contained in:
BecodReyes 2022-04-14 11:05:08 +00:00
parent 21240ed962
commit b23c1b8223
5 changed files with 95 additions and 123 deletions

View File

@ -1,4 +1,4 @@
name: Build Image and Publish to Dockerhub & GPR name: Build Docker Image
on: on:
release: release:
@ -9,109 +9,77 @@ on:
description: 'Image tag' description: 'Image tag'
required: true required: true
default: 'test' default: 'test'
jobs: jobs:
binary: buildx:
name: Build Golang project
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Set up Go 1.x -
uses: actions/setup-go@v2 name: Checkout
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
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Get current date
- name: Build id: date
run: make build run: echo "::set-output name=today::$(date +'%Y-%m-%d')"
-
- name: Archive artifacts for frpc name: Set up QEMU
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
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v1
-
- name: Set up Docker Buildx name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v1
-
# download binaries of frpc and frps name: Available platforms
- name: Download binary of frpc run: echo ${{ steps.buildx.outputs.platforms }}
uses: actions/download-artifact@v2 -
with: name: Get Image Tag Name
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
run: | run: |
if [ x${{ github.event.inputs.tag }} == x"" ]; then if [ x${{ github.event.inputs.tag }} == x"" ]; then
echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
else else
echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
fi fi
-
# prepare image tags name: Login to DockerHub
- name: Prepare Image Tags uses: docker/login-action@v1
run: | with:
echo "DOCKERFILE_FRPC_PATH=dockerfiles/Dockerfile-for-frpc" >> $GITHUB_ENV username: ${{ secrets.DOCKERHUB_USERNAME }}
echo "DOCKERFILE_FRPS_PATH=dockerfiles/Dockerfile-for-frps" >> $GITHUB_ENV password: ${{ secrets.DOCKERHUB_PASSWORD }}
echo "TAG_FRPC=fatedier/frpc:${{ env.TAG_NAME }}" >> $GITHUB_ENV -
echo "TAG_FRPS=fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV name: Login to the GPR
echo "TAG_FRPC_GPR=ghcr.io/fatedier/frpc:${{ env.TAG_NAME }}" >> $GITHUB_ENV uses: docker/login-action@v1
echo "TAG_FRPS_GPR=ghcr.io/fatedier/frps:${{ env.TAG_NAME }}" >> $GITHUB_ENV with:
registry: ghcr.io
# build images username: ${{ github.actor }}
- name: Build Images password: ${{ secrets.GITHUB_TOKEN }}
run: | -
# for Docker hub name: Build and push frpc
docker build --file ${{ env.DOCKERFILE_FRPC_PATH }} --tag ${{ env.TAG_FRPC }} . uses: docker/build-push-action@v2
docker build --file ${{ env.DOCKERFILE_FRPS_PATH }} --tag ${{ env.TAG_FRPS }} . with:
# for GPR context: .
docker build --file ${{ env.DOCKERFILE_FRPC_PATH }} --tag ${{ env.TAG_FRPC_GPR }} . file: ./Dockerfile.frpc
docker build --file ${{ env.DOCKERFILE_FRPS_PATH }} --tag ${{ env.TAG_FRPS_GPR }} . platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
push: ${{ github.event_name != 'pull_request' }}
# push to dockerhub cache-from: type=local,src=/tmp/.buildx-cache
- name: Publish to Dockerhub cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
run: | tags: |
echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin fatedier/frpc:dev
docker push ${{ env.TAG_FRPC }} fatedier/frpc:${{ env.TAG_NAME }}
docker push ${{ env.TAG_FRPS }} fatedier/frpc:${{ steps.date.outputs.today }}
ghcr.io/fatedier/frpc:dev
# push to gpr ghcr.io/fatedier/frpc:${{ env.TAG_NAME }}
- name: Publish to GPR -
run: | name: Build and push frps
echo ${{ secrets.GPR_TOKEN }} | docker login ghcr.io --username ${{ github.repository_owner }} --password-stdin uses: docker/build-push-action@v2
docker push ${{ env.TAG_FRPC_GPR }} with:
docker push ${{ env.TAG_FRPS_GPR }} 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 }}

16
Dockerfile.frpc Normal file
View File

@ -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"]

16
Dockerfile.frps Normal file
View File

@ -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"]

View File

@ -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"]

View File

@ -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"]