Skip to content

Commit

Permalink
perf: 按要求移除重复构建代码
Browse files Browse the repository at this point in the history
  • Loading branch information
wojiushixiaobai authored and LeeEirc committed May 30, 2024
1 parent aa37ab2 commit e5c0962
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
23 changes: 11 additions & 12 deletions .github/workflows/jms-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
component: [lion]
version: [v4]
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v3

- name: Prepare Mirror
- name: Prepare Build
run: |
sed -i 's@registry.npmmirror.com@registry.yarnpkg.com@g' ui/yarn.lock
sed -i 's@registry.fit2cloud.com/@@g' Dockerfile
sed -i 's@^FROM registry.fit2cloud.com/jumpserver@FROM ghcr.io/jumpserver@g' Dockerfile
sed -i 's@^FROM registry.fit2cloud.com/jumpserver@FROM ghcr.io/jumpserver@g' Dockerfile-ee
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -33,34 +38,28 @@ jobs:
context: .
push: true
file: Dockerfile
tags: ghcr.io/jumpserver/lion:v4-lite
tags: ghcr.io/jumpserver/${{ matrix.component }}:${{ matrix.version }}-ce
platforms: linux/amd64
build-args: |
VERSION=v4
VERSION=${{ matrix.version }}
GOPROXY=direct
APT_MIRROR=http://deb.debian.org
NPM_REGISTRY=https://registry.yarnpkg.com
outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Prepare EE Image
run: |
sed -i 's@^FROM registry.fit2cloud.com/jumpserver@FROM ghcr.io/jumpserver@g' Dockerfile-ee

- name: Build EE Image
uses: docker/build-push-action@v5
with:
context: .
push: false
file: Dockerfile-ee
tags: jumpserver/lion:v4
tags: ghcr.io/jumpserver/${{ matrix.component }}:${{ matrix.version }}
platforms: linux/amd64
build-args: |
VERSION=v4
GOPROXY=direct
VERSION=${{ matrix.version }}
APT_MIRROR=http://deb.debian.org
NPM_REGISTRY=https://registry.yarnpkg.com
outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true
cache-from: type=gha
cache-to: type=gha,mode=max
32 changes: 16 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ RUN set -ex \
&& yarn config set registry ${NPM_REGISTRY}

WORKDIR /opt/lion/ui
ADD ui/package.json ui/yarn.lock .
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked \

RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=lion \
--mount=type=bind,source=ui/package.json,target=package.json \
--mount=type=bind,source=ui/yarn.lock,target=yarn.lock \
yarn install

ADD ui .
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked \
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=lion \
yarn build

FROM golang:1.22-bullseye as stage-build
Expand All @@ -31,25 +33,23 @@ RUN set -ex \
&& chmod 755 /usr/local/bin/check \
&& rm -f check-${CHECK_VERSION}-linux-${TARGETARCH}.tar.gz

WORKDIR /opt/lion

ADD go.mod go.sum .

ARG GOPROXY=https://goproxy.io
ENV CGO_ENABLED=0
ENV GO111MODULE=on
ENV GOOS=linux

RUN --mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod \
go mod download -x
WORKDIR /opt/lion

RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked,id=lion \
--mount=type=bind,source=go.mod,target=go.mod \
--mount=type=bind,source=go.sum,target=go.sum \
go mod download

COPY . .

ARG VERSION
ENV VERSION=$VERSION

RUN --mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod \
RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked,id=lion \
export GOFlAGS="-X 'main.Buildstamp=`date -u '+%Y-%m-%d %I:%M:%S%p'`'" \
&& export GOFlAGS="${GOFlAGS} -X 'main.Githash=`git rev-parse HEAD`'" \
&& export GOFlAGS="${GOFlAGS} -X 'main.Goversion=`go version`'" \
Expand All @@ -58,7 +58,7 @@ RUN --mount=type=cache,target=/root/.cache \

RUN chmod +x entrypoint.sh

FROM registry.fit2cloud.com/jumpserver/guacd:1.5.5-bullseye
FROM jumpserver/guacd:1.5.5-bullseye
ARG TARGETARCH
ENV LANG=en_US.UTF-8

Expand All @@ -69,8 +69,8 @@ ARG DEPENDENCIES=" \
supervisor"

ARG APT_MIRROR=http://mirrors.ustc.edu.cn
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=lion \
--mount=type=cache,target=/var/lib/apt,sharing=locked,id=lion \
set -ex \
&& rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache \
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile-ee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG VERSION

FROM registry.fit2cloud.com/jumpserver/lion:${VERSION}-lite
FROM registry.fit2cloud.com/jumpserver/lion:${VERSION}-ce
ARG TARGETARCH

ARG DEPENDENCIES=" \
Expand All @@ -10,8 +10,8 @@ ARG DEPENDENCIES=" \
vim \
wget"

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=lion \
--mount=type=cache,target=/var/lib/apt,sharing=locked,id=lion \
set -ex \
&& apt-get update \
&& apt-get install -y --no-install-recommends ${DEPENDENCIES}

0 comments on commit e5c0962

Please sign in to comment.