🎉 reduce docker image build time

Merge pull request #238 from naiba/dev
This commit is contained in:
naiba 2022-07-07 15:13:39 +08:00 committed by GitHub
commit f9f0857eb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 17 deletions

View File

@ -15,6 +15,35 @@ jobs:
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@master
- name: Extract branch name
run: |
export BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})
echo "##[set-output name=branch;]$BRANCH_NAME"
if [ $BRANCH_NAME = "main" ] || [ $BRANCH_NAME = "master" ]
then echo "##[set-output name=tag;]latest"
else echo "##[set-output name=tag;]$BRANCH_NAME"
fi
id: extract_branch
- name: xgo build
uses: crazy-max/ghaction-xgo@v2
with:
xgo_version: latest
go_version: 1.18
dest: dist
pkg: cmd/dashboard
prefix: dashboard
targets: linux/amd64,linux/arm64,linux/arm-7,linux/s390x,linux/riscv64 # linux/386,
v: true
x: false
race: false
ldflags: -s -w
buildmode: default
- name: fix dist
run: |
cp dist/dashboard-linux-arm-7 dist/dashboard-linux-arm
- name: Log in to the GHCR - name: Log in to the GHCR
uses: docker/login-action@master uses: docker/login-action@master
with: with:
@ -51,8 +80,8 @@ jobs:
with: with:
context: . context: .
file: ./Dockerfile file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm,linux/386,linux/s390x platforms: linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/riscv64 # linux/386,
push: true push: true
tags: | tags: |
${{ steps.image-name.outputs.GHRC_IMAGE_NAME }} ${{ steps.image-name.outputs.GHRC_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
${{ steps.image-name.outputs.ALI_IMAGE_NAME }} ${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}

View File

@ -1,22 +1,22 @@
FROM golang:alpine AS binarybuilder FROM ubuntu:focal
RUN apk --no-cache --no-progress add \
gcc git musl-dev
WORKDIR /dashboard
COPY . .
RUN cd cmd/dashboard && go build -o app -ldflags="-s -w"
FROM alpine:latest
ENV TZ="Asia/Shanghai" ENV TZ="Asia/Shanghai"
ARG TARGETOS
ARG TARGETARCH
COPY ./script/entrypoint.sh /entrypoint.sh COPY ./script/entrypoint.sh /entrypoint.sh
RUN apk --no-cache --no-progress add \
ca-certificates \ RUN export DEBIAN_FRONTEND="noninteractive" && \
tzdata && \ apt update && apt install -y ca-certificates tzdata && \
cp "/usr/share/zoneinfo/$TZ" /etc/localtime && \ update-ca-certificates && \
echo "$TZ" > /etc/timezone && \ ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && \
dpkg-reconfigure tzdata && \
chmod +x /entrypoint.sh chmod +x /entrypoint.sh
WORKDIR /dashboard WORKDIR /dashboard
COPY ./resource ./resource COPY ./resource ./resource
COPY --from=binarybuilder /dashboard/cmd/dashboard/app ./app COPY dist/dashboard-${TARGETOS}-${TARGETARCH} ./app
VOLUME ["/dashboard/data"] VOLUME ["/dashboard/data"]
EXPOSE 80 5555 EXPOSE 80 5555

View File

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
echo -e "nameserver 127.0.0.11\nnameserver 8.8.8.8\nnameserver 223.5.5.5\n" > /etc/resolv.conf echo -e "nameserver 127.0.0.11\nnameserver 8.8.4.4\nnameserver 223.5.5.5\n" > /etc/resolv.conf
/dashboard/app /dashboard/app