Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
DotNet Core for ARM

Build .NET on Windows or Linux, then re-build with Docker on ARM

On your PC:

faas-cli new --lang csharp pinetes

Edit ./pinetes/FunctionHandler.cs

Console.WriteLine("Pi there! "+ input);

Edit ./template/csharp/Dockerfile

Add -r linux-arm to the end of the dotnet publish command

RUN dotnet publish -c release -o published

Comment out all other lines in the file

Run a build:

faas-cli build -f pinetes.yml

Extract the binary folder:

docker create --name pinetes pinetes docker cp pinetes:/root/src/published .

Now scp the file to the RPi:

scp -r published pi@of-1.local:~

On your PI

Log into the RPi

ssh pi@of-1.local

faas-cli new --lang Dockerfile pinetes
mv published pinetes/

Now create the Dockerfile:

FROM microsoft/dotnet:2.0.0-runtime-stretch-arm32v7

RUN echo "Pulling watchdog binary from Github." \
    && curl -sSL https://github.com/openfaas/faas/releases/download/0.6.5/fwatchdog-armhf > /usr/bin/fwatchdog \
    && chmod +x /usr/bin/fwatchdog
WORKDIR /root/
COPY published  published
WORKDIR /root/published

ENV fprocess "dotnet root.dll"

CMD ["/usr/bin/fwatchdog"]

Edit pinetes.yml with your Docker hub account name

At this point you can now build, push and deploy as per usual. For the next build of the .NET code on your laptop only repeat the steps below:

faas-cli build -f pinetes.yml
faas-cli push -f pinetes.yml
faas-cli deploy -f pinetes.yml --gateway http://127.0.0.1:31112

.NET is pretty big so the deployment may take a while. Once it's in place you can invoke it like this:

curl 127.0.0.1:31112/function/pinetes -d test
Pi there! test

If you want to watch for the deployment type in watch kubectl get pods

watch kubectl get pods


NAME                            READY     STATUS              RESTARTS   AGE
alertmanager-56d9c57b48-7qjjr   1/1       Running             0          1d
faas-netesd-78597bdfdd-ngrl8    1/1       Running             0          1d
gateway-f9bd744fb-4jvj6         1/1       Running             0          1d

pinetes-5997656d58-g8c4h        0/1       ContainerCreating   0          26s

On your PC

faas-cli new --lang csharp pinetes

Edit ./pinetes/FunctionHandler.cs

Console.WriteLine("Pi there! "+ input);

Edit ./template/csharp/Dockerfile

FROM microsoft/dotnet:2.0-sdk as builder

ENV DOTNET_CLI_TELEMETRY_OPTOUT 1

# Optimize for Docker builder caching by adding projects first.

RUN mkdir -p /root/src/function
WORKDIR /root/src/function
COPY ./function/Function.csproj  .

WORKDIR /root/src/
COPY ./root.csproj  .
RUN dotnet restore ./root.csproj

COPY .  .

RUN dotnet publish -c release -o published -r linux-arm

ADD https://github.com/openfaas/faas/releases/download/0.6.1/fwatchdog-armhf /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog

FROM microsoft/dotnet:2.0.0-runtime-stretch-arm32v7

WORKDIR /root/
COPY --from=builder /root/src/published .
COPY --from=builder /usr/bin/fwatchdog /

ENV fprocess="dotnet ./root.dll"
EXPOSE 8080
CMD ["/fwatchdog"]

Edit pinetes.yml and set your Docker Hub name

faas-cli build -f pinetes.yml --parallel=1
faas-cli push -f pinetes.yml
faas-cli deploy -f pinetes.yml --gateway http://127.0.0.1:31112

Replace the gateway IP with the IP of the Kubernetes master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment