Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 5 additions & 106 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,99 +6,16 @@ on:
- master

jobs:
detect_changes:
name: Detect changed microservices
runs-on: ubuntu-latest
outputs:
changed_services: ${{ steps.set-matrix.outputs.changed_services }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for Git tags

- name: Detect changed files
id: changes
uses: tj-actions/changed-files@v45
with:
files: |
Services/**
Common/**

- name: Determine changed services
id: set-matrix
run: |
echo "All changed files:"
echo "${{ steps.changes.outputs.all_modified_files }}"

ALL_SERVICES=("Devices" "Raports" "Measurements" "Emulators" "Gateways")
CHANGED_FILES="${{ steps.changes.outputs.all_modified_files }}"

# If anything changed in Common → rebuild all services
if echo "$CHANGED_FILES" | grep -q "^Common/"; then
echo "Common changed → rebuilding all microservices."
JSON=$(printf '"%s",' "${ALL_SERVICES[@]}" | sed 's/,$//')
echo "changed_services=[$JSON]" >> $GITHUB_OUTPUT
exit 0
fi

# Detect individual service changes
SERVICES=()
for folder in "${ALL_SERVICES[@]}"; do
if echo "$CHANGED_FILES" | grep -q "Services/$folder"; then
SERVICES+=("\"$folder\"")
fi
done

if [ ${#SERVICES[@]} -eq 0 ]; then
echo "changed_services=[]" >> $GITHUB_OUTPUT
exit 0
fi

JSON="[$(IFS=,; echo "${SERVICES[*]}")]"
echo "Detected changed microservices: $JSON"
echo "changed_services=$JSON" >> $GITHUB_OUTPUT

build_and_push:
name: Build, push Docker images and create Git tags
needs: detect_changes
if: needs.detect_changes.outputs.changed_services != '[]'
name: Build and push Docker images
runs-on: ubuntu-latest
strategy:
matrix:
service: ${{ fromJson(needs.detect_changes.outputs.changed_services) }}
service: [Devices, Measurements, Raports, Emulators, Gateways]

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

- name: Determine Docker tag for service
id: version
run: |
SERVICE="${{ matrix.service }}"

# Get latest Git tag for this service
LAST_TAG=$(git tag --list "${SERVICE}-v*" --sort=-v:refname | head -n 1)

if [ -z "$LAST_TAG" ]; then
NEXT_TAG="v1.0.0"
else
VERSION=${LAST_TAG#${SERVICE}-}
MAJOR=${VERSION%%.*}
MINOR=$(echo $VERSION | cut -d. -f2)
PATCH=$(echo $VERSION | cut -d. -f3)
PATCH=$((PATCH+1))
NEXT_TAG="$MAJOR.$MINOR.$PATCH"
fi

echo "Service: $SERVICE"
echo "Last tag: $LAST_TAG"
echo "Next Docker tag: $NEXT_TAG"

echo "NEXT_TAG=$NEXT_TAG" >> $GITHUB_ENV

- name: Build Docker image
run: |
Expand All @@ -120,9 +37,8 @@ jobs:
exit 1
fi

echo "Building Docker image for $SERVICE:${NEXT_TAG}"
docker build -f $DOCKERFILE -t darekkrawczyk/homee.server.$SERVICE_LOWER:${NEXT_TAG} .

echo "Building Docker image for $SERVICE"
docker build -f $DOCKERFILE -t darekkrawczyk/homee.server.$SERVICE_LOWER:latest .

- name: Push Docker image
env:
Expand All @@ -132,21 +48,4 @@ jobs:
SERVICE_LOWER=$(echo "$SERVICE" | tr '[:upper:]' '[:lower:]')

echo $DOCKERHUB_TOKEN | docker login -u darekkrawczyk --password-stdin
docker push darekkrawczyk/homee.server.$SERVICE_LOWER:${NEXT_TAG}

- name: Create Git tag for service
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
SERVICE="${{ matrix.service }}"
TAG_NAME="${SERVICE}-${NEXT_TAG}"

git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists, skipping."
else
git tag "$TAG_NAME"
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}" "$TAG_NAME"
fi
docker push darekkrawczyk/homee.server.$SERVICE_LOWER:latest
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="Google.Protobuf" Version="3.31.1" />
<PackageReference Include="Grpc.Core" Version="2.46.6" />
<PackageReference Include="Grpc.Net.Client" Version="2.71.0" />
<PackageReference Include="Grpc.Net.Client.Web" Version="2.71.0" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.71.0" />
<PackageReference Include="Grpc.Tools" Version="2.72.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
31 changes: 17 additions & 14 deletions Services/Devices/Devices.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
var builder = WebApplication.CreateBuilder(args);

builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

builder.Configuration.AddEnvironmentVariables();

if (builder.Environment.IsDevelopment())
{
builder.Configuration.AddUserSecrets<Program>();
}

builder.Services.AddInfrastructureServices(builder.Configuration, builder.Environment);
builder.Services.AddApplicationServices(builder.Configuration, builder.Environment);
builder.Services.AddGRPCServerServices(builder.Configuration);

builder.Services.AddHealthChecks();


builder.Services.AddCors(options =>
{

options.AddDefaultPolicy(policy =>
{
policy.WithOrigins("http://localhost:5173")
var corsOrigins = builder.Configuration.GetSection("CorsOrigins").Get<string[]>();

policy.WithOrigins(corsOrigins)
.AllowAnyHeader()
.AllowCredentials()
.AllowAnyMethod();
.AllowAnyMethod()
.AllowCredentials();
});
});

builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddUserSecrets<Program>();

var app = builder.Build();

bool initializeDB = app.Configuration["InitializeDBOnStart"] == "true" ? true : false;

if (app.Environment.IsDevelopment() && initializeDB)
{
await app.InitializeDatabaseAsync();
}

app.AddApplicationServicesUsage();
app.AddGRPCServerServicesUsage();

app.UseRouting();

app.UseCors();

app.MapHealthChecks("/devices/health", new HealthCheckOptions
Expand Down
1 change: 0 additions & 1 deletion Services/Devices/Devices.API/README.md

This file was deleted.

8 changes: 6 additions & 2 deletions Services/Devices/Devices.API/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
},
"CorsOrigins": [
"http://localhost:5173",
"http://localhost:3000"
]
}
10 changes: 10 additions & 0 deletions Services/Devices/Devices.API/appsettings.Production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"CorsOrigins": [
"https://homeesystem.azurewebsites.net"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@ public static IServiceCollection AddGRPCServerServices(this IServiceCollection s
.Map(dest => dest.Id, src => src.ID)
.Map(dest => dest.Type, src => src.Type);

//TypeAdapterConfig<MeasurementConfiguration, GrpcMeasurementConfiguration>
// .NewConfig()
// .Map(dest => dest.Id, src => src.ID)
// .Map(dest => dest.Temperature, src => src.Temperature)
// .Map(dest => dest.Humidity, src => src.Humidity)
// .Map(dest => dest.CarbonDioxide, src => src.CarbonDioxide)
// .Map(dest => dest.VolatileOrganicCompounds, src => src.VolatileOrganicCompounds)
// .Map(dest => dest.Pm1, src => src.PM1)
// .Map(dest => dest.Pm25, src => src.PM25)
// .Map(dest => dest.Pm10, src => src.PM10)
// .Map(dest => dest.Formaldehyde, src => src.Formaldehyde)
// .Map(dest => dest.CarbonMonoxide, src => src.CarbonMonoxide)
// .Map(dest => dest.Ozone, src => src.Ozone)
// .Map(dest => dest.Ammonia, src => src.Ammonia)
// .Map(dest => dest.Airflow, src => src.Airflow)
// .Map(dest => dest.AirIonizationLevel, src => src.AirIonizationLevel)
// .Map(dest => dest.Oxygen, src => src.Oxygen)
// .Map(dest => dest.Radon, src => src.Radon)
// .Map(dest => dest.Illuminance, src => src.Illuminance)
// .Map(dest => dest.SoundLevel, src => src.SoundLevel);

TypeAdapterConfig<Timestamp, GrpcTimestampConfigurationModel>
.NewConfig()
.Map(dest => dest.Id, src => src.ID)
Expand All @@ -60,6 +39,7 @@ public static IServiceCollection AddGRPCServerServices(this IServiceCollection s

public static WebApplication AddGRPCServerServicesUsage(this WebApplication app)
{
app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true });
app.MapGrpcService<DevicesServerService>();

return app;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.71.0" />
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.71.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading