Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can F# type provides be used with containerized (Docker) resources?

I know how one can use certain F# type providers, e.g. SQLProvider for non-Docker development: #if DEBUG, connect to a local database, otherwise connect to the production database. Or, if the type provider supports it (as with SQLProvider), specify a connection string in a configuration file. In both cases however, the database is available at build time (as it has to be).

However, I have just started using Docker containers, and I fail to see how type providers can be used when the database is only available in another container at runtime (e.g. through a private network created by docker-compose). For development, although certainly not ideal, I can get around this by having the same database set up locally (outside Docker) just so the type provider can get the schema. When deploying, however, the database need to be available, but my understanding is that while docker-compose will start the containers in dependency order, actually building the containers happens in complete isolation.

Are there good ways to use type providers for accessing containerized databases?

like image 368
cmeeren Avatar asked May 24 '18 06:05

cmeeren


People also ask

Is Kevin can f himself Cancelled?

On November 30, 2021, AMC confirmed the series would conclude after two seasons.

Who is Nick on Kevin can f himself?

Robin Lord Taylor: Nick Wyndorff.

Is Patty Kevin's sister?

Allison and Kevin's neighbor, and Neil's sister, Patty (Mary Hollis Inboden) pops in from time to time. Although not exactly friends with Allison, she is the only one who tends to come to Allison's defense in this clear patriarchy.


2 Answers

You could use multi-stage docker build. Setup one "building" docker image with database in it, and pass-through built assemblies you want to use. Here is the short example from our code base.

# BUILDER IMAGE (with DB in it)
FROM microsoft/dotnet:2-sdk-jessie as builder

RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

RUN echo "deb http://download.mono-project.com/repo/debian jessie main" > /etc/apt/sources.list.d/mono-official.list

RUN apt-get update && apt-get install -y \ 
    mono-devel

ADD ./ /app
WORKDIR /app

RUN ./build.sh Publish

# FINAL IMAGE
FROM microsoft/dotnet:runtime

COPY --from=builder /app/deploy/ app/

WORKDIR ./app/
CMD ["dotnet", "MY_AMAZING_APP.dll"]

Some lines are maybe not neccessary not (it is quite old code base), but just to give you some hint. The important part is COPY --from=builder. Hope it helps.

like image 189
Dzoukr Avatar answered Oct 16 '22 15:10

Dzoukr


Depending on the type provider in question, you can also avoid the build dependency on another running system by using hardcoded or file samples that are always available locally.

For example in case of JSON type provider you can provide a text file with sample objects to make sure you can build even if a remote web service is not reachable.

With SQLProvider it should be possible using the ContextSchemaPath parameter in a manner similar to this excellent article: https://medium.com/real-world-fsharp/continuous-integration-with-type-providers-6ddf40ee31b3

like image 2
Honza Brestan Avatar answered Oct 16 '22 14:10

Honza Brestan