Evolve icon indicating copy to clipboard operation
Evolve copied to clipboard

Are there any plans to create a docker image?

Open AnderssonPeter opened this issue 3 years ago • 6 comments

Hi are there any plans to create a docker image of evolve, this would be awesome when running Continues deployments?

AnderssonPeter avatar Dec 06 '21 14:12 AnderssonPeter

This produces a bunch of Trim analysis warnings, so I don't know if it actually works for all providers. I did some minimal tests against postgres and sqlite, YMMV.

FROM mcr.microsoft.com/dotnet/sdk:6.0.101-alpine3.14 as build
WORKDIR /build

COPY build/ build/
COPY src/ src/

RUN dotnet publish \
    --configuration Release \
    --framework net6.0 \
    --runtime linux-x64 \
    --self-contained \
    -p:PublishSingleFile=true \
    -p:PublishTrimmed=true \
    -p:IncludeNativeLibrariesForSelfExtract=true \
    src/Evolve.Tool/Evolve.Tool.csproj

RUN dotnet publish \
    --configuration Release \
    --framework net6.0 \
    --runtime linux-musl-x64 \
    --self-contained \
    -p:PublishSingleFile=true \
    -p:PublishTrimmed=true \
    -p:IncludeNativeLibrariesForSelfExtract=true \
    src/Evolve.Tool/Evolve.Tool.csproj

FROM debian:11.2-slim as evolve-bullseye
RUN apt-get update && apt-get install -y --no-install-recommends libicu67 && rm -rf /var/lib/apt/lists/*
COPY --from=build /build/src/Evolve.Tool/bin/Release/net6.0/linux-x64/publish/Evolve.Tool /usr/local/bin/evolve
ENTRYPOINT [ "evolve" ]

FROM alpine:3.15 as evolve-alpine
RUN apk add --update --no-cache libgcc libstdc++ icu
COPY --from=build /build/src/Evolve.Tool/bin/Release/net6.0/linux-musl-x64/publish/Evolve.Tool /usr/local/bin/evolve
ENTRYPOINT [ "evolve" ]

Build

docker build --target evolve-bullseye --tag evolve-bullseye .
docker build --target evolve-alpine --tag evolve-alpine .

Size

  • Alpine: 28.2M Jan 7 12:11 /usr/local/bin/evolve
  • Debian: 29M Jan 7 12:02 /usr/local/bin/evolve

SQLite sample

Set-StrictMode -Version Latest
$connection="Data Source=test.db;Version=3;"

docker run -it --rm `
    --mount src="$(pwd)\db",target=/db,type=bind,readonly `
    --mount src="$(pwd)\test.db",target=/test.db,type=bind `
    evolve-alpine migrate sqlite -l db -c "$connection"

if (-not $?) { throw "Migrate failed" }

peterhirn avatar Jan 07 '22 12:01 peterhirn

Your example is good, but I am not sure I want to build from source. It would be nice to replace the build segments with a simple dotnet tool install --global Evolve.Tool. I am working on installing and using in CI as well. I will post any progress I make here.

ctoestreich avatar Feb 09 '22 23:02 ctoestreich

This example could help also: https://github.com/lecaillon/Evolve/issues/253#issuecomment-1008131273

lecaillon avatar Feb 13 '22 08:02 lecaillon

@ctoestreich Usually you want to avoid dotnet tool in production containers because it depends on the .net sdk which is unnecessary bloat.

mcr.microsoft.com/dotnet/sdk   6.0.102-alpine3.14-amd64   9536e3d32191   4 days ago      578MB

The Dockerfile I posted above is sub-optimal:

  • Remove -p:IncludeNativeLibrariesForSelfExtract=true as it doesn't matter in a container and probably affects startup performance.
  • Use https://hub.docker.com/_/microsoft-dotnet-runtime-deps/ as base which is specifically built for self-contained apps and avoids installing icu, see https://github.com/dotnet/dotnet-docker/blob/main/src/runtime-deps/3.1/alpine3.14/amd64/Dockerfile

@lecaillon I did setup a test repo (.net hello world) to experiment with docker and github actions here: https://github.com/peterhirn/testing-actions. I was thinking about creating a PR for evolve, but have some questions:

  • are you ok with adding github actions or would you prefer to have everything in appveyor?
  • what architectures would you like to support? In my sample repo I'm building amd64, arm/v7, arm64 and -musl variants, but I don't have a raspberry pi to test the output. ¯\_(ツ)_/¯

peterhirn avatar Feb 13 '22 10:02 peterhirn

Hey @peterhirn What do you have in mind with those GitHub actions. Not sure to fully understand

lecaillon avatar Feb 14 '22 20:02 lecaillon

Hi. I would add this action https://github.com/peterhirn/testing-actions/blob/main/.github/workflows/docker.yaml to build and push docker images on release. This requires two additional files: Dockerfile and docker-bake.hcl

The action produces images like https://hub.docker.com/r/peter87623/testing-actions/tags

  • alpine + bullseye
  • three architectures mentioned above
  • semver versions (1 + 1.0 + 1.0.1, or prereleases 1.0.14-rc.1-alpine)

peterhirn avatar Feb 16 '22 07:02 peterhirn