Browse Source

perf: 按要求移除重复构建代码

pull/13342/head
吴小白 6 months ago committed by 老广
parent
commit
3536af2051
  1. 43
      .github/workflows/jms-build-test.yml
  2. 52
      Dockerfile
  3. 29
      Dockerfile-ee
  4. 55
      Dockerfile.base

43
.github/workflows/jms-build-test.yml

@ -11,8 +11,12 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
matrix:
component: [core]
version: [v4]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3 - uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
@ -21,21 +25,10 @@ jobs:
registry: ghcr.io registry: ghcr.io
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Base Image - name: Prepare Build
uses: docker/build-push-action@v5 run: |
with: sed -i 's@^FROM registry.fit2cloud.com/jumpserver@FROM ghcr.io/jumpserver@g' Dockerfile-ee
context: .
push: true
file: Dockerfile.base
tags: ghcr.io/jumpserver/core:v4-base
platforms: linux/amd64
build-args: |
APT_MIRROR=http://deb.debian.org
PIP_MIRROR=https://pypi.org/simple
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: Build CE Image - name: Build CE Image
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
@ -43,34 +36,28 @@ jobs:
context: . context: .
push: true push: true
file: Dockerfile file: Dockerfile
tags: ghcr.io/jumpserver/core:v4-lite tags: ghcr.io/jumpserver/${{ matrix.component }}:${{ matrix.version }}-ce
platforms: linux/amd64 platforms: linux/amd64
build-args: | build-args: |
VERSION=v4 VERSION=${{ matrix.version }}
APT_MIRROR=http://deb.debian.org APT_MIRROR=http://deb.debian.org
BASE_IMAGE=ghcr.io/jumpserver/core PIP_MIRROR=https://pypi.org/simple
outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
- name: Prepare EE Image
run: |
sed -i 's@^FROM registry.fit2cloud.com/jumpserver/xpack@# FROM registry.fit2cloud.com/jumpserver/xpack@' Dockerfile-ee
sed -i 's@^FROM registry.fit2cloud.com/jumpserver@FROM ghcr.io/jumpserver@g' Dockerfile-ee
sed -i 's@^COPY --from=build-xpack@# COPY --from=build-xpack@g' Dockerfile-ee
- name: Build EE Image - name: Build EE Image
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
context: . context: .
push: false push: false
file: Dockerfile-ee file: Dockerfile-ee
tags: jumpserver/core:v4 tags: ghcr.io/jumpserver/${{ matrix.component }}:${{ matrix.version }}
platforms: linux/amd64 platforms: linux/amd64
build-args: | build-args: |
VERSION=v4 VERSION=${{ matrix.version }}
APT_MIRROR=http://deb.debian.org APT_MIRROR=http://deb.debian.org
BASE_IMAGE=ghcr.io/jumpserver/core PIP_MIRROR=https://pypi.org/simple
outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max

52
Dockerfile

@ -1,7 +1,4 @@
ARG VERSION FROM debian:bullseye-slim as stage-1
ARG BASE_IMAGE=jumpserver/core
FROM python:3.11-slim-bullseye as stage-1
ARG TARGETARCH ARG TARGETARCH
ARG DEPENDENCIES=" \ ARG DEPENDENCIES=" \
@ -9,8 +6,8 @@ ARG DEPENDENCIES=" \
wget" wget"
ARG APT_MIRROR=http://mirrors.ustc.edu.cn ARG APT_MIRROR=http://mirrors.ustc.edu.cn
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=core \
--mount=type=cache,target=/var/lib/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked,id=core \
set -ex \ set -ex \
&& rm -f /etc/apt/apt.conf.d/docker-clean \ && rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache \ && echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache \
@ -48,15 +45,42 @@ RUN echo > /opt/jumpserver/config.yml \
sed -i "s@VERSION = .*@VERSION = '${VERSION}'@g" apps/jumpserver/const.py; \ sed -i "s@VERSION = .*@VERSION = '${VERSION}'@g" apps/jumpserver/const.py; \
fi fi
FROM ${BASE_IMAGE}:${VERSION}-base as stage-2 FROM python:3.11-slim-bullseye as stage-2
ARG TARGETARCH ARG TARGETARCH
ARG BUILD_DEPENDENCIES=" \
g++ \
make \
pkg-config"
ARG DEPENDENCIES=" \
default-libmysqlclient-dev \
gettext \
libldap2-dev \
libsasl2-dev"
ARG APT_MIRROR=http://mirrors.ustc.edu.cn
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=core \
--mount=type=cache,target=/var/lib/apt,sharing=locked,id=core \
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 ${BUILD_DEPENDENCIES} \
&& apt-get -y install --no-install-recommends ${DEPENDENCIES} \
&& echo "no" | dpkg-reconfigure dash
WORKDIR /opt/jumpserver WORKDIR /opt/jumpserver
RUN --mount=type=cache,target=/root/.cache,sharing=locked \ ARG PIP_MIRROR=https://pypi.tuna.tsinghua.edu.cn/simple
--mount=type=bind,source=poetry.lock,target=/opt/jumpserver/poetry.lock \ RUN --mount=type=cache,target=/root/.cache,sharing=locked,id=core \
--mount=type=bind,source=pyproject.toml,target=/opt/jumpserver/pyproject.toml \ --mount=type=bind,source=poetry.lock,target=poetry.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
set -ex \ set -ex \
&& python3 -m venv /opt/py3 \
&& pip install poetry -i ${PIP_MIRROR} \
&& poetry config virtualenvs.create false \
&& . /opt/py3/bin/activate \ && . /opt/py3/bin/activate \
&& poetry install --only main && poetry install --only main
@ -75,9 +99,7 @@ ENV LANG=en_US.UTF-8 \
ARG DEPENDENCIES=" \ ARG DEPENDENCIES=" \
libldap2-dev \ libldap2-dev \
libpq-dev \ libx11-dev"
libx11-dev \
libxmlsec1-openssl"
ARG TOOLS=" \ ARG TOOLS=" \
ca-certificates \ ca-certificates \
@ -86,8 +108,8 @@ ARG TOOLS=" \
sshpass" sshpass"
ARG APT_MIRROR=http://mirrors.ustc.edu.cn ARG APT_MIRROR=http://mirrors.ustc.edu.cn
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=core \
--mount=type=cache,target=/var/lib/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked,id=core \
set -ex \ set -ex \
&& rm -f /etc/apt/apt.conf.d/docker-clean \ && rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache \ && echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache \

29
Dockerfile-ee

@ -1,20 +1,35 @@
ARG VERSION ARG VERSION
ARG BASE_IMAGE=registry.fit2cloud.com/jumpserver/core
FROM registry.fit2cloud.com/jumpserver/xpack:${VERSION} as build-xpack FROM registry.fit2cloud.com/jumpserver/xpack:${VERSION} as build-xpack
FROM registry.fit2cloud.com/jumpserver/core:${VERSION}-base as build-core FROM python:3.11-slim-bullseye as build-core
ARG TARGETARCH ARG BUILD_DEPENDENCIES=" \
g++"
ARG APT_MIRROR=http://mirrors.ustc.edu.cn
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=core \
--mount=type=cache,target=/var/lib/apt,sharing=locked,id=core \
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 ${BUILD_DEPENDENCIES} \
&& echo "no" | dpkg-reconfigure dash
WORKDIR /opt/jumpserver WORKDIR /opt/jumpserver
RUN --mount=type=cache,target=/root/.cache,sharing=locked \ ARG PIP_MIRROR=https://pypi.tuna.tsinghua.edu.cn/simple
RUN --mount=type=cache,target=/root/.cache,sharing=locked,id=core \
--mount=type=bind,source=poetry.lock,target=/opt/jumpserver/poetry.lock \ --mount=type=bind,source=poetry.lock,target=/opt/jumpserver/poetry.lock \
--mount=type=bind,source=pyproject.toml,target=/opt/jumpserver/pyproject.toml \ --mount=type=bind,source=pyproject.toml,target=/opt/jumpserver/pyproject.toml \
set -ex \ set -ex \
&& python3 -m venv /opt/py3 \
&& pip install poetry -i ${PIP_MIRROR} \
&& poetry config virtualenvs.create false \
&& . /opt/py3/bin/activate \ && . /opt/py3/bin/activate \
&& poetry install --only xpack && poetry install --only xpack
FROM ${BASE_IMAGE}:${VERSION}-lite FROM registry.fit2cloud.com/jumpserver/core:${VERSION}-ce
ARG TARGETARCH ARG TARGETARCH
ARG TOOLS=" \ ARG TOOLS=" \
@ -27,8 +42,8 @@ ARG TOOLS=" \
wget" wget"
ARG APT_MIRROR=http://mirrors.ustc.edu.cn ARG APT_MIRROR=http://mirrors.ustc.edu.cn
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=core \
--mount=type=cache,target=/var/lib/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked,id=core \
set -ex \ set -ex \
&& apt-get update \ && apt-get update \
&& apt-get -y install --no-install-recommends ${TOOLS} && apt-get -y install --no-install-recommends ${TOOLS}

55
Dockerfile.base

@ -1,55 +0,0 @@
FROM python:3.11-slim-bullseye
ARG TARGETARCH
ARG BUILD_DEPENDENCIES=" \
g++ \
make \
pkg-config"
ARG DEPENDENCIES=" \
freetds-dev \
gettext \
libffi-dev \
libjpeg-dev \
libkrb5-dev \
libldap2-dev \
libpq-dev \
libsasl2-dev \
libssl-dev \
libxml2-dev \
libxmlsec1-dev \
libxmlsec1-openssl \
freerdp2-dev \
libaio-dev"
ARG TOOLS=" \
ca-certificates \
curl \
default-libmysqlclient-dev \
default-mysql-client \
git \
git-lfs \
unzip \
xz-utils \
wget"
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 \
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 -y install --no-install-recommends ${BUILD_DEPENDENCIES} \
&& apt-get -y install --no-install-recommends ${DEPENDENCIES} \
&& apt-get -y install --no-install-recommends ${TOOLS} \
&& echo "no" | dpkg-reconfigure dash
ARG PIP_MIRROR=https://pypi.org/simple
RUN --mount=type=cache,target=/root/.cache,sharing=locked \
set -ex \
&& python3 -m venv /opt/py3 \
&& pip install poetry -i ${PIP_MIRROR} \
&& poetry config virtualenvs.create false
Loading…
Cancel
Save