Skip to content

Commit

Permalink
perf: 按要求移除重复构建代码
Browse files Browse the repository at this point in the history
  • Loading branch information
wojiushixiaobai committed May 30, 2024
1 parent faf169d commit 53cc221
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 70 deletions.
35 changes: 24 additions & 11 deletions .github/workflows/jms-build-test.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
name: "Run Build Test"
on:
push:
branches:
- pr@*
- repr@*
paths:
- 'Dockerfile'
- 'Dockerfile*'
- 'Dockerfile-*'

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
component: [web]
version: [v4]
steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v3
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3

- name: Prepare Build
run: |
sed -i 's@^FROM registry.fit2cloud.com@# FROM registry.fit2cloud.com@g' Dockerfile Dockerfile-ee
sed -i 's@^COPY --from=@# COPY --from=@g' Dockerfile Dockerfile-ee
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
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build CE Image
uses: docker/build-push-action@v5
with:
context: .
push: false
push: true
file: Dockerfile
tags: jumpserver/web-ce:test
tags: ghcr.io/jumpserver/${{ matrix.component }}:${{ matrix.version }}-ce
platforms: linux/amd64
build-args: |
VERSION=${{ matrix.version }}
APT_MIRROR=http://deb.debian.org
outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true
cache-from: type=gha
cache-to: type=gha,mode=max

Expand All @@ -37,9 +50,9 @@ jobs:
context: .
push: false
file: Dockerfile-ee
tags: jumpserver/web-ee:test
tags: jumpserver/${{ matrix.component }}:${{ matrix.version }}
platforms: linux/amd64
build-args: |
APT_MIRROR=http://deb.debian.org
VERSION=${{ matrix.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
17 changes: 13 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ FROM registry.fit2cloud.com/jumpserver/lina:${VERSION} as lina
FROM registry.fit2cloud.com/jumpserver/luna:${VERSION} as luna
FROM registry.fit2cloud.com/jumpserver/applets:${VERSION} as applets

FROM debian:bookworm-slim as stage-build
FROM debian:bullseye-slim as stage-build
ARG TARGETARCH

ARG DEPENDENCIES=" \
ca-certificates \
wget"

RUN set -ex \
ARG APT_MIRROR=http://mirrors.ustc.edu.cn
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=web \
--mount=type=cache,target=/var/lib/apt,sharing=locked,id=web \
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 \
&& sed -i "s@http://.*.debian.org@${APT_MIRROR}@g" /etc/apt/sources.list \
&& apt-get update \
&& apt-get -y install --no-install-recommends ${DEPENDENCIES} \
&& echo "no" | dpkg-reconfigure dash \
Expand All @@ -33,8 +39,11 @@ ARG TARGETARCH

ARG APT_MIRROR=http://mirrors.ustc.edu.cn
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=web \
sed -i "s@http://.*.debian.org@${APT_MIRROR}@g" /etc/apt/sources.list \
&& rm -f /etc/cron.daily/apt-compat \
--mount=type=cache,target=/var/lib/apt,sharing=locked,id=web \
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 \
&& sed -i "s@http://.*.debian.org@${APT_MIRROR}@g" /etc/apt/sources.list \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& apt-get update \
&& apt-get install -y --no-install-recommends wget vim logrotate locales \
Expand Down
57 changes: 2 additions & 55 deletions Dockerfile-ee
Original file line number Diff line number Diff line change
@@ -1,58 +1,5 @@
ARG VERSION
FROM registry.fit2cloud.com/jumpserver/web-static:v4.0.0 as static
FROM registry.fit2cloud.com/jumpserver/lina:${VERSION} as lina
FROM registry.fit2cloud.com/jumpserver/luna:${VERSION} as luna
FROM registry.fit2cloud.com/jumpserver/applets:${VERSION} as applets
FROM registry.fit2cloud.com/jumpserver/web:${VERSION}-ce

FROM debian:bookworm-slim as stage-build
ARG TARGETARCH

ARG DEPENDENCIES=" \
ca-certificates \
wget"

RUN set -ex \
&& apt-get update \
&& apt-get -y install --no-install-recommends ${DEPENDENCIES} \
&& echo "no" | dpkg-reconfigure dash \
&& apt-get clean all \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /opt

ARG CHECK_VERSION=v1.0.2
RUN set -ex \
&& wget https://github.com/jumpserver-dev/healthcheck/releases/download/${CHECK_VERSION}/check-${CHECK_VERSION}-linux-${TARGETARCH}.tar.gz \
&& tar -xf check-${CHECK_VERSION}-linux-${TARGETARCH}.tar.gz \
&& mv check /usr/local/bin/ \
&& chown root:root /usr/local/bin/check \
&& chmod 755 /usr/local/bin/check \
&& rm -f check-${CHECK_VERSION}-linux-${TARGETARCH}.tar.gz

FROM nginx:1.24-bullseye
ARG TARGETARCH

ARG APT_MIRROR=http://mirrors.ustc.edu.cn
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=web \
sed -i "s@http://.*.debian.org@${APT_MIRROR}@g" /etc/apt/sources.list \
&& rm -f /etc/cron.daily/apt-compat \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& apt-get update \
&& apt-get install -y --no-install-recommends wget vim logrotate locales \
&& echo "no" | dpkg-reconfigure dash \
&& echo "zh_CN.UTF-8" | dpkg-reconfigure locales \
&& rm -f /var/log/nginx/*.log \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /opt

COPY --from=stage-build /usr/local/bin /usr/local/bin
COPY --from=static /opt /opt
COPY --from=lina /opt/lina /opt/lina
COPY --from=luna /opt/luna /opt/luna
COPY --from=applets /opt/applets /opt/download/applets
COPY nginx.conf /etc/nginx/nginx.conf
COPY includes /etc/nginx/includes
COPY default.conf /etc/nginx/conf.d/default.conf
COPY http_server.conf /etc/nginx/sites-enabled/http_server.conf
COPY init.sh /docker-entrypoint.d/40-init-config.sh
COPY --from=static /opt /opt

0 comments on commit 53cc221

Please sign in to comment.