Skip to content

Commit

Permalink
perf: 尝试调试缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
wojiushixiaobai committed Jan 26, 2024
1 parent 6fa0e21 commit 9b12a5c
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 3 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,33 @@ on:
tags:
- '*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
prepare:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: actions/setup-python@v4
with:
python-version: 3.11

- uses: abatilo/actions-poetry@v2

- name: Get Version
run: |
echo "version=$(basename ${GITHUB_REF})" >> $GITHUB_ENV
- name: Generate poetry.lock
run: |
wget https://github.com/jumpserver/jumpserver/raw/${{ env.version }}/pyproject.toml
poetry config virtualenvs.create false
poetry source add --priority=default PyPI
poetry lock --no-update
jobs:
build:
needs: prepare
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build Cache

on:
push:
branches:
- master
schedule:
- cron: '0 1 * * *'

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

- uses: abatilo/actions-poetry@v2

- name: Generate poetry.lock
run: |
wget https://github.com/jumpserver/jumpserver/raw/master/pyproject.toml
poetry config virtualenvs.create false
poetry source add --priority=default PyPI
poetry lock --no-update
- 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 and Push Image
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.component }}/Dockerfile.cache
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/jms_${{ matrix.component }}:cache
cache-from: type=gha
cache-to: type=gha,mode=max
8 changes: 5 additions & 3 deletions core/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM python:3.11-slim-bookworm as stage-1
FROM ghcr.io/wojiushixiaobai/jms_core:cache as stage-2
ARG TARGETARCH

ARG DEPENDENCIES=" \
Expand Down Expand Up @@ -117,7 +118,7 @@ RUN set -ex \
cd /opt && rm -rf /opt/rust-install /opt/rust.tar.gz; \
fi

COPY --from=stage-1 /opt/jumpserver/poetry.lock /opt/jumpserver/pyproject.toml /opt/jumpserver/
COPY --from=stage-2 /root/.cache /root/.cache

WORKDIR /opt/jumpserver

Expand All @@ -126,8 +127,9 @@ ARG PYTHONUNBUFFERED=1 \

ENV GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1

RUN --mount=type=cache,target=/root/.cache \
set -ex \
RUN --mount=type=bind,source=poetry.lock,target=/opt/jumpserver/poetry.lock \
--mount=type=bind,source=pyproject.toml,target=/opt/jumpserver/pyproject.toml \
set -ex \
&& python3 -m venv /opt/py3 \
&& pip install $(grep cryptography pyproject.toml | sed 's/ = /==/g' | sed 's/"//g') \
&& pip install poetry \
Expand Down
92 changes: 92 additions & 0 deletions core/Dockerfile.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
FROM python:3.11-slim-bookworm
ARG TARGETARCH

ARG BUILD_DEPENDENCIES=" \
g++ \
make \
pkg-config"

ARG DEPENDENCIES=" \
freetds-dev \
libpq-dev \
libffi-dev \
libjpeg-dev \
libldap2-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"

RUN set -ex \
&& 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 \
&& apt-get clean all \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /opt

ARG RUST_VERSION=1.71.1
RUN set -ex \
&& mkdir -p /opt/rust-install \
&& rustUrl="https://static.rust-lang.org/dist" \
&& \
case "${TARGETARCH}" in \
# amd64) rustArch='x86_64-unknown-linux-gnu'; \
# ;; \
# arm64) rustArch='aarch64-unknown-linux-gnu'; \
# ;; \
mips64le) rustArch='mips64el-unknown-linux-gnuabi64'; \
;; \
ppc64le) rustArch='powerpc64le-unknown-linux-gnu'; \
;; \
riscv64) rustArch='riscv64gc-unknown-linux-gnu'; \
;; \
s390x) rustArch='s390x-unknown-linux-gnu'; \
;; \
loong64) rustArch='loongarch64-unknown-linux-gnu'; \
rustUrl="https://download.jumpserver.org/rust/dist"; \
;; \
*) echo >&2 "error: unsupported architecture: ${TARGETARCH}"; \
;; \
esac \
&& \
if [ -n "${rustArch}" ]; then \
wget -O /opt/rust.tar.gz "${rustUrl}/rust-${RUST_VERSION}-${rustArch}.tar.xz"; \
tar -xf /opt/rust.tar.gz -C /opt/rust-install --strip-components=1; \
cd /opt/rust-install && ./install.sh; \
cd /opt && rm -rf /opt/rust-install /opt/rust.tar.gz; \
fi

WORKDIR /opt/jumpserver

ARG PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1

ENV GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1

RUN --mount=type=bind,source=poetry.lock,target=/opt/jumpserver/poetry.lock \
--mount=type=bind,source=pyproject.toml,target=/opt/jumpserver/pyproject.toml \
set -ex \
&& python3 -m venv /opt/py3 \
&& pip install $(grep cryptography pyproject.toml | sed 's/ = /==/g' | sed 's/"//g') \
&& pip install poetry \
&& poetry config virtualenvs.create false \
&& . /opt/py3/bin/activate \
&& poetry install --only=main

0 comments on commit 9b12a5c

Please sign in to comment.