Skip to content

Commit e1a2c10

Browse files
fix(builder): the uvicorn logging files are written into the project, where the build context is (#100)
#99 wrote uvicorn-log-config.json and codefly_uvicorn_logging.py into the render directory and COPY'd them from the context root; the build context is the service directory (or the assembled copy of it), so every image build failed at that COPY. They are now written into the project before any context is assembled — exactly where a native start writes them — and copied from code/ beside src. Co-authored-by: Antoine Toussaint <312536060+antoinetoussaint-byte@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 1e51763 commit e1a2c10

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

‎build_recipe_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,7 @@ func TestBuildShipsSiblingPackages(t *testing.T) {
196196
"COPY --chown=appuser code/src code/src",
197197
"COPY --chown=appuser code/adapters code/adapters",
198198
"COPY --chown=appuser code/model_service code/model_service",
199+
// uvicorn's logging configuration and filter, written by the builder (uvicorn_logging.go).
200+
"COPY --chown=appuser code/uvicorn-log-config.json code/codefly_uvicorn_logging.py ./",
199201
}, copies)
200202
}

‎builder.go‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ func (s *Builder) Build(ctx context.Context, req *builderv0.BuildRequest) (*buil
216216
// A project that is a member of a uv workspace in the service is built from
217217
// that workspace, copied whole (see enclosingUVWorkspace); its path sources
218218
// must then stay inside the service the context carries.
219+
// uvicorn's logging configuration and its filter module, written into the
220+
// project exactly as a native start writes them, before any context is
221+
// assembled from it: the build context is the service directory (or the
222+
// assembled copy of it), and the Dockerfile copies them from code/ beside
223+
// src (uvicorn_logging.go).
224+
if err := writeUvicornLogging(s.SourceLocation); err != nil {
225+
return s.Base.Builder.BuildError(err)
226+
}
219227
membership, err := enclosingUVWorkspace(s.Location, s.SourceLocation)
220228
if err != nil {
221229
return s.Base.Builder.BuildError(err)
@@ -259,11 +267,6 @@ func (s *Builder) Build(ctx context.Context, req *builderv0.BuildRequest) (*buil
259267
if err := s.Base.Templates(ctx, docker, services.WithBuilder(builderFS).WithDestination("%s", outputDir)); err != nil {
260268
return s.Base.Builder.BuildError(err)
261269
}
262-
// uvicorn's logging configuration and its filter module, which the
263-
// Dockerfile copies beside the code (uvicorn_logging.go).
264-
if err := writeUvicornLogging(outputDir); err != nil {
265-
return s.Base.Builder.BuildError(err)
266-
}
267270
image := s.DockerImage(dockerRequest).FullName()
268271
if assembled == nil {
269272
// Only the Dockerfile and its ignore were written, and the application's

‎templates/builder/Dockerfile.tmpl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ WORKDIR /app/code
7676

7777
# uvicorn's logging configuration and the filter it names (uvicorn_logging.go):
7878
# health probes are dropped from the access log, everything else is as uvicorn
79-
# writes it. Both files are rendered into the build context by the builder.
80-
COPY --chown=appuser uvicorn-log-config.json codefly_uvicorn_logging.py ./
79+
# writes it. The builder writes both into the project before the build.
80+
COPY --chown=appuser {{.ServicePrefix}}code/uvicorn-log-config.json {{.ServicePrefix}}code/codefly_uvicorn_logging.py ./
8181

8282
# Default REST port (overridden by codefly at runtime).
8383
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8080", "--log-config", "uvicorn-log-config.json"]

0 commit comments

Comments
 (0)