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

View File

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

View File

@@ -9,4 +9,4 @@ RUN chown reflex:reflex /app
USER reflex
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)
WORKDIR /app
COPY requirements.txt .
# Create virtualenv which will be copied into final container
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN python3.11 -m venv $VIRTUAL_ENV
COPY requirements.txt .
# Install app requirements and reflex inside virtualenv
RUN pip install -r requirements.txt

View File

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