optimizing build time
All checks were successful
continuous-integration/drone/push Build is passing

- using cache
- reorder docker build steps
This commit is contained in:
2024-01-05 07:10:16 +01:00
parent f55825fa05
commit 5e3448aa03
5 changed files with 63 additions and 24 deletions

View File

@@ -4,6 +4,20 @@
type: 'docker', type: 'docker',
name: 'reflex-ipad', name: 'reflex-ipad',
steps: [ steps: [
{
name: 'restore-cache',
image: 'drillster/drone-volume-cache',
settings: {
restore: true,
ttl: 7,
mount: [
'/drone/docker',
],
},
volumes: [
{ name: 'cache', path: '/cache' },
],
},
{ {
name: 'builder', name: 'builder',
image: 'plugins/docker', image: 'plugins/docker',
@@ -13,19 +27,23 @@
registry: 'gitea.pb42.de', registry: 'gitea.pb42.de',
repo: 'gitea.pb42.de/matthias/reflex-ipad', repo: 'gitea.pb42.de/matthias/reflex-ipad',
cache_from: 'gitea.pb42.de/matthias/reflex-ipad:builder', cache_from: 'gitea.pb42.de/matthias/reflex-ipad:builder',
storage_path: '/drone/docker',
config: { from_secret: 'dockerconfigjson' }, config: { from_secret: 'dockerconfigjson' },
}, },
depends_on: [
'restore-cache',
],
}, },
{ {
name: 'frontend-builder', name: 'frontend-builder',
image: 'gitea.pb42.de/matthias/reflex-ipad:builder', image: 'gitea.pb42.de/matthias/reflex-ipad:builder',
commands:[ commands: [
'cd /app', 'cd /app',
'reflex export --frontend-only --no-zip', 'reflex export --frontend-only --no-zip',
'mv .web/_static /drone/src/web', 'mv .web/_static /drone/src/web',
], ],
depends_on: [ depends_on: [
'builder' 'builder',
], ],
}, },
{ {
@@ -38,28 +56,46 @@
repo: 'gitea.pb42.de/matthias/reflex-ipad', repo: 'gitea.pb42.de/matthias/reflex-ipad',
config: { from_secret: 'dockerconfigjson' }, config: { from_secret: 'dockerconfigjson' },
build_args: ['API_URL=https://ipad.pb42.de'], build_args: ['API_URL=https://ipad.pb42.de'],
storage_path: '/drone/docker',
}, },
depends_on: [ depends_on: [
'builder' 'builder',
], ],
}, },
{ {
name: "deploy_web", name: 'deploy_web',
image: "appleboy/drone-scp", image: 'appleboy/drone-scp',
settings: { settings: {
host: "pb42.de", host: 'pb42.de',
target: "/", target: '/',
source: "web/*", source: 'web/*',
username: { username: {
from_secret: "deploy_username", from_secret: 'deploy_username',
}, },
key: { key: {
from_secret: "deploy_key", from_secret: 'deploy_key',
}, },
port: 42022, port: 42022,
}, },
depends_on: [ depends_on: [
'frontend-builder' 'frontend-builder',
],
},
{
name: 'rebuild-cache',
image: 'drillster/drone-volume-cache',
settings: {
rebuild: true,
mount: [
'/drone/docker',
],
},
volumes: [
{ name: 'cache', path: '/cache' },
],
depends_on: [
'builder',
'backend',
], ],
}, },
{ {
@@ -84,19 +120,26 @@
stack: 'reflex-ipad', stack: 'reflex-ipad',
file: 'docker-compose.yml', file: 'docker-compose.yml',
standalone: true, standalone: true,
swarmId: "", swarmId: '',
type: 2, type: 2,
environment: [], environment: [],
env: [], env: [],
debug: true, debug: true,
}, },
depends_on: [ depends_on: [
'backend', 'backend',
], ],
}, },
], ],
volumes: [
{
name: 'cache',
host: {
path: '/tmp/cache',
},
},
],
trigger: { event: ['push'] }, trigger: { event: ['push'] },
image_pull_secrets: ['dockerconfigjson'], image_pull_secrets: ['dockerconfigjson'],
}, },
] ]

View File

@@ -1,22 +1,18 @@
# Stage 1: init # Stage 1: init
FROM python:3.11 as init FROM python:3.11 as init
# Pass `--build-arg API_URL=http://app.example.com:8000` during build
ARG API_URL ARG API_URL
# Copy local context to `/app` inside container (see .dockerignore)
WORKDIR /app WORKDIR /app
COPY requirements.txt .
# Create virtualenv which will be copied into final container
ENV VIRTUAL_ENV=/app/.venv ENV VIRTUAL_ENV=/app/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH" ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN python3.11 -m venv $VIRTUAL_ENV RUN python3.11 -m venv $VIRTUAL_ENV
# Install app requirements and reflex inside virtualenv COPY requirements.txt .
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
COPY . . COPY . .
# Deploy templates and prepare app
RUN reflex init RUN reflex init

View File

@@ -9,4 +9,4 @@ RUN chown reflex:reflex /app
USER reflex USER reflex
ENV PATH="/app/.venv/bin:$PATH" API_URL=$API_URL PYTHONUNBUFFERED=TRUE ENV PATH="/app/.venv/bin:$PATH" API_URL=$API_URL PYTHONUNBUFFERED=TRUE
CMD reflex db migrate && reflex run --env dev --backend-only CMD reflex db migrate && reflex run --env prod --backend-only

View File

@@ -6,13 +6,13 @@ ARG API_URL
# Copy local context to `/app` inside container (see .dockerignore) # Copy local context to `/app` inside container (see .dockerignore)
WORKDIR /app WORKDIR /app
COPY requirements.txt .
# Create virtualenv which will be copied into final container
ENV VIRTUAL_ENV=/app/.venv ENV VIRTUAL_ENV=/app/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH" ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN python3.11 -m venv $VIRTUAL_ENV RUN python3.11 -m venv $VIRTUAL_ENV
COPY requirements.txt .
# Install app requirements and reflex inside virtualenv # Install app requirements and reflex inside virtualenv
RUN pip install -r requirements.txt RUN pip install -r requirements.txt

View File

@@ -4,7 +4,7 @@ config = rx.Config(
app_name="reflex_ipad", app_name="reflex_ipad",
db_url="postgresql://ipad:uizJOcDZR3qKLUJuAeSr8WG8onJ1vsUQB2zgE5NIKcpLGT5EF3x7JBkPs@db:5432/ipad", db_url="postgresql://ipad:uizJOcDZR3qKLUJuAeSr8WG8onJ1vsUQB2zgE5NIKcpLGT5EF3x7JBkPs@db:5432/ipad",
api_url="https://ipad.pb42.de", api_url="https://ipad.pb42.de",
env=rx.Env.DEV, env=rx.Env.PROD,
loglevel="debug", loglevel="debug",
telemetry_enabled=False, telemetry_enabled=False,
) )