Skip to content

Commit

Permalink
Initial docker work #4
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbouetsmith committed Jul 3, 2024
1 parent 8983f87 commit 5b53923
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Source/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/bin/*
**/obj/*
**/out/*
**/.vs/*
**/_ReSharper.Caches/*
8 changes: 8 additions & 0 deletions Source/Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@
<PackageReference Include="ROOT.Zfs.Core" Version="1.1.10" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.Docker.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
</Project>
20 changes: 19 additions & 1 deletion Source/Api/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

**Prequisites**
# Prequisites

Requires ZFS installed on the server

Expand Down Expand Up @@ -37,3 +37,21 @@ cd /mnt/zfsapi/zfsapi
tr -d '\r' < /mnt/zfsapi/zfsapi/1.2.3/deploy.sh > /mnt/zfsapi/zfsapi/deploy.sh

sudo sh /mnt/zfsapi/zfsapi/deploy.sh 1.2.3 all

# Docker

You can also run the api in a docker container


Simply open a shell/powershell/cmd whatever up on the Source folder and run the following command to build the image

```bash
docker build -t zfs-api:1.1.10 -f './Dockerfile'
```

Where you change the version tag to whatever version you want.

## TODO
* ssh keys needs to be installed in the docker environment
Can most likely just be done by creating a filesystem that copies your wanted .ssh folder to /root/.ssh in the container
* Username/password auth
17 changes: 17 additions & 0 deletions Source/Api/appsettings.Docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"Remote": {
"UseRemoteConnection": true,
"HostName": "zfsdev.root.dom",
"UserName": "bbs",
"UseSudo": true
},
"Logging": {
"LogLevel": {
"Default": "Trace",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"UseLinuxAuth": false
}
32 changes: 32 additions & 0 deletions Source/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# create build environment in /Build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /Build

# Copy source files
COPY ./Api/* ./Api/

# Build and publish to /Build/out
RUN dotnet build Api/Api.csproj -c Release --framework net6.0 --runtime linux-x64

RUN dotnet publish Api/Api.csproj --no-build -c Release --framework net6.0 --sc --runtime linux-x64 -o out
CMD ls -l
FROM mcr.microsoft.com/dotnet/aspnet:8.0

# install required packages
run apt-get update

#required to get linux auth working
run apt-get -y install libpam0g-dev

#required for remote connections to the zfs server
run apt-get -y install ssh

# Create app dir /App and copy publishing output to /App
WORKDIR /App
COPY --from=build-env /Build/out .

# Tell docker we will be exposing port 5000
EXPOSE 5000/TCP

# run the api in the asp.net environment Docker, which corresponds to the appsettings.Docker.json
ENTRYPOINT ["dotnet","Api.dll","--environment=Docker"]
2 changes: 2 additions & 0 deletions Source/ROOT.Zfs.Api.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Github", "Github", "{BEDD26
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4912DE71-350A-4036-B203-CC7A1CFD3513}"
ProjectSection(SolutionItems) = preProject
.dockerignore = .dockerignore
Dockerfile = Dockerfile
..\README.md = ..\README.md
EndProjectSection
EndProject
Expand Down

0 comments on commit 5b53923

Please sign in to comment.