Skip to content

Commit

Permalink
Merge branch 'develop' into convert-to-https
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleypayton committed Mar 20, 2024
2 parents 2ec66c7 + dcfa592 commit 65714ba
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 16 deletions.
9 changes: 9 additions & 0 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Problem
<!--Add a description and the userstory prompt-->

## Definition of Done

## Subtasks
- [x] Subtask 1
- [x] Subtask 2
- [x] etc.
11 changes: 11 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Fixes #ISSUE_NUMBER

## Problem

### Definition of Done

## Solution

## Documentation

## How was this tested?
42 changes: 42 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and Push Docker Image

on:
push:
branches:
- test

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check Out Repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/focusapi

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: src/FocusAPI/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
6 changes: 6 additions & 0 deletions FocusFriends.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FocusApp.Client", "src\Focu
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FocusApp.Tools", "src\FocusApp.Tools\FocusApp.Tools.csproj", "{C37B9511-E73B-4E1D-BBA4-6D160872381C}"
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{47A7CE9C-83C5-4EB4-AD59-6931446410E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -52,6 +54,10 @@ Global
{C37B9511-E73B-4E1D-BBA4-6D160872381C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C37B9511-E73B-4E1D-BBA4-6D160872381C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C37B9511-E73B-4E1D-BBA4-6D160872381C}.Release|Any CPU.Build.0 = Release|Any CPU
{47A7CE9C-83C5-4EB4-AD59-6931446410E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47A7CE9C-83C5-4EB4-AD59-6931446410E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47A7CE9C-83C5-4EB4-AD59-6931446410E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47A7CE9C-83C5-4EB4-AD59-6931446410E6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
19 changes: 19 additions & 0 deletions docker-compose.dcproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
<PropertyGroup Label="Globals">
<ProjectVersion>2.1</ProjectVersion>
<DockerTargetOS>Linux</DockerTargetOS>
<DockerPublishLocally>False</DockerPublishLocally>
<ProjectGuid>86154e51-9282-4e60-92ef-598eb64d9bd1</ProjectGuid>
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}/swagger</DockerServiceUrl>
<DockerServiceName>focusapi</DockerServiceName>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" />
<None Include=".dockerignore" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.4'

services:
FocusApi:
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/home/app/.aspnet/https:ro
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3.4'

networks:
FocusApiNetwork:

services:
FocusApi:
container_name: FocusApiContainer
image: ghcr.io/chrispypeaches/focusfriends/focusapi:test
ports:
- 25565:8080
- 25566:8081
build:
context: .
dockerfile: src/FocusAPI/Dockerfile
depends_on:
- FocusApiDb
environment:
ASPNETCORE_URLS: "http://+:8080"
ASPNETCORE_ENVIRONMENT: Test
ASPNETCORE_HTTP_PORTS: 8080
ASPNETCORE_HTTPS_PORTS: 8081
env_file:
- stack.env
FocusApiDb:
container_name: FocusApiDbContainer
image: mcr.microsoft.com/mssql/server:2022-latest
ports:
- 8002:1433
environment:
- ACCEPT_EULA=Y
env_file:
- stack.env
11 changes: 11 additions & 0 deletions launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"profiles": {
"Docker Compose": {
"commandName": "DockerCompose",
"commandVersion": "1.0",
"serviceActions": {
"focusapi": "StartDebugging"
}
}
}
}
23 changes: 19 additions & 4 deletions src/FocusAPI/Data/FocusContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using FocusAPI.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;

namespace FocusAPI.Data;

Expand All @@ -15,10 +17,23 @@ public class FocusContext : DbContext
public DbSet<Furniture> Furniture { get; set; }
public DbSet<Sound> Sounds { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
/// <summary>
/// If the database isn't created, create it.
/// If the tables aren't created, create them.
/// </summary>
public FocusContext(DbContextOptions<FocusContext> options) : base(options)
{
// No SQL server conneciton yet
// Better alternative for SQL Server connection https://learn.microsoft.com/en-us/ef/core/miscellaneous/connection-strings
optionsBuilder.UseSqlServer(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=FocusFriendsDevTest;Integrated Security=True;");
if (Database.GetService<IDatabaseCreator>() is RelationalDatabaseCreator dbCreator)
{
if (!dbCreator.CanConnect())
{
dbCreator.Create();
}

if (!dbCreator.HasTables())
{
dbCreator.CreateTables();
}
}
}
}
7 changes: 4 additions & 3 deletions src/FocusAPI/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["FocusFriends/FocusAPI/FocusAPI.csproj", "FocusFriends/FocusAPI/"]
RUN dotnet restore "./FocusFriends/FocusAPI/./FocusAPI.csproj"
COPY ["src/FocusAPI/FocusAPI.csproj", "src/FocusAPI/"]
COPY ["src/FocusCore/FocusCore.csproj", "src/FocusCore/"]
RUN dotnet restore "./src/FocusAPI/./FocusAPI.csproj"
COPY . .
WORKDIR "/src/FocusFriends/FocusAPI"
WORKDIR "/src/src/FocusAPI"
RUN dotnet build "./FocusAPI.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
Expand Down
1 change: 1 addition & 0 deletions src/FocusAPI/FocusAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<UserSecretsId>28bb837f-63e7-4996-96dd-e0f320b54000</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
<DockerComposeProjectPath>..\..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>

<ItemGroup>
Expand Down
15 changes: 12 additions & 3 deletions src/FocusAPI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using FluentValidation;
using MediatR;
using System.Reflection;
using System.Runtime.CompilerServices;
using FocusAPI.Configuration.PipelineBehaviors;
using FocusCore.Validators.Users;
using FocusAPI.Data;
using FocusCore.Validators.Users;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -22,12 +24,19 @@
// Register FocusCore assembly containing validators with FluentValidation
builder.Services.AddValidatorsFromAssembly(Assembly.GetAssembly(typeof(CreateUserValidator)));

builder.Services.AddDbContext<FocusContext>();
// Register DbContext
builder.Services.AddDbContext<FocusContext>(options =>
{
options.UseSqlServer(builder.Configuration["DefaultConnectionString"]);
});

var app = builder.Build();

// Instantiate the DbContext so that the database is created if it doesn't exist
_ = app.Services.GetService<FocusContext>();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
if (!app.Environment.IsProduction())
{
app.UseSwagger();
app.UseSwaggerUI();
Expand Down
7 changes: 1 addition & 6 deletions src/FocusAPI/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
"publishAllPorts": true
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
Expand Down
1 change: 1 addition & 0 deletions src/FocusAPI/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"DefaultConnectionString": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=DEV_FocusApiDb;Integrated Security=True;",
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
8 changes: 8 additions & 0 deletions src/FocusAPI/appsettings.Test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

0 comments on commit 65714ba

Please sign in to comment.