Skip to content

Commit

Permalink
Add dev.Dockerfile for FwHeadless (#1201)
Browse files Browse the repository at this point in the history
* Add dev.Dockerfile for FwHeadless

* Use dev.Dockerfile in Tilt

* Cache dotnet restore the way api Dockerfile does

* Don't rebuild LexBoxApi when FwHeadless changes

---------

Co-authored-by: Kevin Hahn <[email protected]>
  • Loading branch information
rmunn and hahn-kev authored Nov 5, 2024
1 parent 9348bdc commit 6a5a04d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ docker_build(
context='backend',
dockerfile='./backend/LexBoxApi/dev.Dockerfile',
only=['.'],
ignore=['FwHeadless'],
live_update=[
sync('backend', '/src/backend'),
sync('backend', '/src/backend')
]
)

docker_build(
'ghcr.io/sillsdev/lexbox-fw-headless',
context='backend',
dockerfile='./backend/FwHeadless/Dockerfile',
dockerfile='./backend/FwHeadless/dev.Dockerfile',
only=['.'],
ignore=['LexBoxApi'],
live_update=[
sync('backend', '/src/backend'),
sync('backend', '/src/backend')
]
)

Expand Down
4 changes: 2 additions & 2 deletions backend/FwHeadless/FwHeadless.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</ItemGroup>

<ItemGroup>
<Content Include="Mercurial\**" CopyToOutputDirectory="Always" />
<Content Include="MercurialExtensions\**" CopyToOutputDirectory="Always" />
<Content Include="Mercurial\**" CopyToOutputDirectory="Always" Watch="false" />
<Content Include="MercurialExtensions\**" CopyToOutputDirectory="Always" Watch="false" />
</ItemGroup>
</Project>
48 changes: 48 additions & 0 deletions backend/FwHeadless/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
EXPOSE 80
EXPOSE 443
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update && apt-get --no-install-recommends install -y tini iputils-ping python3
RUN mkdir -p /var/lib/fw-headless /var/www/.local/share && chown -R www-data:www-data /var/lib/fw-headless /var/www/
USER www-data:www-data
WORKDIR /src/backend
# Uncomment line below if second COPY fails
# RUN mkdir -p FwLite && chown www-data:www-data FwLite
# Copy the main source project files
COPY --chown=www-data:www-data *.sln FwHeadless/FwHeadless.csproj FixFwData/FixFwData.csproj LexCore/LexCore.csproj LexData/LexData.csproj ./
# move them into the proper sub folders, based on the name of the project
RUN for file in $(ls *.csproj); do dir=${file%.*}; mkdir -p ${dir}/ && mv -v $file ${dir}/; done
# Do the same for csproj files in slightly different hierarchies
COPY --chown=www-data:www-data harmony/src/*/*.csproj ./
RUN for file in $(ls *.csproj); do dir=${file%.*}; mkdir -p harmony/src/${dir}/ && mv -v $file harmony/src/${dir}/; done
COPY --chown=www-data:www-data harmony/src/Directory.Build.props ./harmony/src/
COPY --chown=www-data:www-data FwLite/FwDataMiniLcmBridge/FwDataMiniLcmBridge.csproj FwLite/LcmCrdt/LcmCrdt.csproj FwLite/MiniLcm/MiniLcm.csproj FwLite/FwLiteProjectSync/FwLiteProjectSync.csproj ./
RUN for file in $(ls *.csproj); do dir=${file%.*}; mkdir -p FwLite/${dir}/ && mv -v $file FwLite/${dir}/; done

ARG CACHE_LOCATION=/src/dotnet-cache
RUN --mount=type=cache,target=$CACHE_LOCATION,uid=33,gid=33 \
cp -r $CACHE_LOCATION/.local $CACHE_LOCATION/.nuget /var/www/ || true

# Now that all csproj files are in place, restore them
RUN dotnet restore FwHeadless/FwHeadless.csproj

#the cache needs to be stored in the image,
#so we can't use the cache on the restore command, so we back it up to the cache here

RUN --mount=type=cache,target=$CACHE_LOCATION,uid=33,gid=33 \
cp -r /var/www/.local /var/www/.nuget $CACHE_LOCATION/

COPY --chown=www-data:www-data . .
WORKDIR /src/backend/FwHeadless
#build here so that the build is run before container start, need to make sure the property is set both here
#and in the CMD command, otherwise it will rebuild every time the container starts
RUN dotnet build --property:InformationalVersion=dockerDev

#ensures the shutdown happens quickly
ENTRYPOINT ["tini", "--"]

ENV ASPNETCORE_ENVIRONMENT=Development
# no need to restore because we already restored as part of building the image
CMD dotnet watch run --property:InformationalVersion=dockerDev --no-restore --non-interactive
2 changes: 1 addition & 1 deletion skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build:
- image: ghcr.io/sillsdev/lexbox-fw-headless
context: backend
docker:
dockerfile: FwHeadless/Dockerfile
dockerfile: FwHeadless/dev.Dockerfile
- image: ghcr.io/sillsdev/lexbox-ui
context: frontend
docker:
Expand Down

0 comments on commit 6a5a04d

Please sign in to comment.