Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from Etherna/feature/BEET-2-build-docker-image
Browse files Browse the repository at this point in the history
Feature/beet 2 build docker image
  • Loading branch information
tmm360 authored Oct 8, 2024
2 parents fbab37b + f40125a commit 952393d
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 30 deletions.
6 changes: 3 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**/.dockerignore
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
Expand All @@ -22,4 +22,4 @@
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
README.md
43 changes: 43 additions & 0 deletions .github/workflows/stable-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Stable release on Docker Hub

on:
push:
tags:
- 'v*.*.*'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: etherna/bee-turbo
tags: |
type=semver,pattern=v{{major}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{version}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
41 changes: 41 additions & 0 deletions .github/workflows/unstable-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Unstable release on Docker Hub

on:
push:
branches:
- dev

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: etherna/bee-turbo
tags: |
type=ref,event=branch
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
7 changes: 7 additions & 0 deletions BeeTurbo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeeTurbo", "src\BeeTurbo\Be
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BC8B908F-0A65-4E3D-BD12-1F38C87BBC43}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{8AC33738-1D77-4D8C-AF20-2BB2FA69D024}"
ProjectSection(SolutionItems) = preProject
.github\workflows\unstable-release.yml = .github\workflows\unstable-release.yml
.github\workflows\stable-release.yml = .github\workflows\stable-release.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -24,5 +30,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{41265068-0289-4718-A0C0-7BE6D0E7EC34} = {BC8B908F-0A65-4E3D-BD12-1F38C87BBC43}
{8AC33738-1D77-4D8C-AF20-2BB2FA69D024} = {D24883E6-EC9D-48F5-9977-AFDC9900EA80}
EndGlobalSection
EndGlobal
15 changes: 5 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
EXPOSE 1633

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["src/BeeTurbo/BeeTurbo.csproj", "src/BeeTurbo/"]
RUN dotnet restore "src/BeeTurbo/BeeTurbo.csproj"
COPY . .
WORKDIR "/src/src/BeeTurbo"
RUN dotnet build "BeeTurbo.csproj" -c $BUILD_CONFIGURATION -o /app/build
RUN dotnet restore "BeeTurbo.sln"
RUN dotnet build "BeeTurbo.sln" -c Release -o /app/build
RUN dotnet test "BeeTurbo.sln" -c Release

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "BeeTurbo.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
RUN dotnet publish "BeeTurbo.sln" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
Expand Down
18 changes: 10 additions & 8 deletions src/BeeTurbo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,37 @@ namespace Etherna.BeeTurbo
{
public static class Program
{
public const string LocalBeeNodeAddress = "http://localhost:1633/";

static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

// Get config.
var beeUrl = builder.Configuration["BeeUrl"] ??
throw new ArgumentException("BeeUrl is not defined");

// Configs.
ConfigureServices(builder);
ConfigureServices(builder, beeUrl);

var app = builder.Build();
ConfigureApplication(app);
ConfigureApplication(app, beeUrl);

// Run application.
app.Run();
}

private static void ConfigureServices(WebApplicationBuilder builder)
private static void ConfigureServices(WebApplicationBuilder builder, string beeUrl)
{
var services = builder.Services;

services.AddHttpForwarder();

// Singleton services.
services.AddSingleton<IBeeClient>(_ => new BeeClient(new Uri(LocalBeeNodeAddress, UriKind.Absolute)));
services.AddSingleton<IBeeClient>(_ => new BeeClient(new Uri(beeUrl, UriKind.Absolute)));
services.AddSingleton<IChunkStreamTurboProcessor, ChunkStreamTurboProcessor>();
}

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope")]
private static void ConfigureApplication(WebApplication app)
private static void ConfigureApplication(WebApplication app, string beeUrl)
{
app.UseRouting();
app.UseWebSockets(new WebSocketOptions
Expand Down Expand Up @@ -88,7 +90,7 @@ await processer.HandleWebSocketConnection(
await httpContext.Response.WriteAsync("Expected a WebSocket request");
}
});
app.MapForwarder("/{**catch-all}", LocalBeeNodeAddress);
app.MapForwarder("/{**catch-all}", beeUrl);
}
}
}
8 changes: 0 additions & 8 deletions src/BeeTurbo/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:14233",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
Expand Down
3 changes: 2 additions & 1 deletion src/BeeTurbo/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
},
"BeeUrl" : "http://localhost:1633/"
}
3 changes: 3 additions & 0 deletions src/BeeTurbo/appsettings.Production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"HTTP_PORTS": "1633"
}

0 comments on commit 952393d

Please sign in to comment.