Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature CI Docker Compose #7

Merged
merged 17 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
a59f840
Add .dockerignore file to exclude unnecessary files from Docker builds
sentemon Nov 14, 2024
104e22a
Simplify Docker image build and push steps in GitHub Actions workflow
sentemon Nov 15, 2024
62ed935
Add Docker support for PostService with Dockerfile and docker-compose…
sentemon Nov 15, 2024
fe2eb9d
Refactor Dockerfile and docker-compose configuration for improved bui…
sentemon Nov 16, 2024
b707781
Enhance GitHub Actions workflow to build Docker images from the src d…
sentemon Nov 16, 2024
4d77244
Add environment variable support for Docker builds and update connect…
sentemon Nov 16, 2024
0c0d702
Use Docker Buildx for building images in GitHub Actions workflow
sentemon Nov 16, 2024
a5c12b0
Fix Docker build arguments
sentemon Nov 16, 2024
810ffd8
Update Dockerfile and configuration for improved connection handling …
sentemon Nov 16, 2024
202db53
Add Docker Compose start step and health check endpoint to workflow a…
sentemon Nov 16, 2024
c39f9ad
Fix health check endpoint URL in GitHub Actions workflow
sentemon Nov 16, 2024
1fcb757
Fix health check endpoint in GitHub Actions workflow and update Docke…
sentemon Nov 16, 2024
68e75c7
Update health check endpoint in GitHub
sentemon Nov 16, 2024
c2181fd
Update health check implementation and service configuration in workf…
sentemon Nov 17, 2024
1b9be3f
Add delay to health check in GitHub Actions workflow
sentemon Nov 17, 2024
33357e0
Add logging of open ports in GitHub Actions workflow
sentemon Nov 17, 2024
f8a5b40
Remove logging of open ports and update health check URL in GitHub Ac…
sentemon Nov 17, 2024
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
295 changes: 295 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@

# Created by https://www.gitignore.io/api/csharp

### Csharp ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
project.fragment.lock.json
artifacts/
Properties/launchSettings.json

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# Visual Studio code coverage results
*.coverage
*.coveragexml

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# Paket dependency manager
.paket/paket.exe
paket-files/

# FAKE - F# Make
.fake/

# JetBrains Rider
.idea/
*.sln.iml

# CodeRush
.cr/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc

# Cake - Uncomment if you are using it
# tools/
tools/Cake.CoreCLR
.vscode
tools
.dotnet
Dockerfile

# .env file contains default environment variables for docker
.env
.git/


node_modules
npm-debug.log
Dockerfile*
docker-compose*
.dockerignore
.gitignore
README.md
LICENSE
27 changes: 17 additions & 10 deletions .github/workflows/post.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,25 @@ jobs:

- name: Build Docker image
run: |
IMAGE_VERSION="latest"
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
IMAGE_VERSION=${GITHUB_REF#refs/tags/}
docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/post-service:${IMAGE_VERSION} -f ./backend/src/PostService/Dockerfile ./backend
else
echo "Skipping Docker image build because this is not a tag push."
IMAGE_VERSION=${GITHUB_REF#refs/tags/}
fi
docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/post-service:${IMAGE_VERSION} -f ./backend/src/PostService/Dockerfile ./backend/src

- name: Push Docker image to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: |
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
IMAGE_VERSION=${GITHUB_REF#refs/tags/}
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/post-service:${IMAGE_VERSION}
else
echo "Skipping Docker image push because this is not a tag push."
fi
IMAGE_VERSION=${GITHUB_REF#refs/tags/}
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/post-service:${IMAGE_VERSION}

docker-compose:
needs: docker
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build Docker Compose
run: docker compose build --no-cache
sentemon marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions FitnessApp.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PostService", "backend\PostService", "{84AE3F00-9A59-4A8D-A737-67AB74E5D1FD}"
ProjectSection(SolutionItems) = preProject
backend\src\PostService\Dockerfile = backend\src\PostService\Dockerfile
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PostService.Api", "backend\src\PostService\PostService.Api\PostService.Api.csproj", "{2E44C019-ED30-4671-A878-D2F7B6071024}"
EndProject
Expand Down Expand Up @@ -33,7 +36,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{D5A1
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution-items", "solution-items", "{CE086396-E7FB-46F7-87A9-4570DBF43597}"
ProjectSection(SolutionItems) = preProject
.dockerignore = .dockerignore
.gitignore = .gitignore
docker-compose.yml = docker-compose.yml
LICENSE = LICENSE
README.md = README.md
EndProjectSection
Expand Down
23 changes: 12 additions & 11 deletions backend/src/PostService/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@ WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

WORKDIR /src

COPY ["FitnessApp.sln", "./"]
COPY ["src/PostService/PostService.Api/PostService.Api.csproj", "src/PostService/PostService.Api/"]
COPY ["src/PostService/PostService.Application/PostService.Application.csproj", "src/PostService/PostService.Application/"]
COPY ["src/PostService/PostService.Domain/PostService.Domain.csproj", "src/PostService/PostService.Domain/"]
COPY ["src/PostService/PostService.Infrastructure/PostService.Infrastructure.csproj", "src/PostService/PostService.Infrastructure/"]
COPY ["src/PostService/PostService.Persistence/PostService.Persistence.csproj", "src/PostService/PostService.Persistence/"]
COPY ["src/Shared/Shared.Application/Shared.Application.csproj", "src/Shared/Shared.Application/"]
COPY PostService/PostService.Api/PostService.Api.csproj PostService/PostService.Api/
COPY PostService/PostService.Application/PostService.Application.csproj PostService/PostService.Application/
COPY PostService/PostService.Domain/PostService.Domain.csproj PostService/PostService.Domain/
COPY PostService/PostService.Infrastructure/PostService.Infrastructure.csproj PostService/PostService.Infrastructure/
COPY PostService/PostService.Persistence/PostService.Persistence.csproj PostService/PostService.Persistence/
COPY Shared/Shared.Application/Shared.Application.csproj Shared/Shared.Application/

RUN dotnet restore "src/PostService/PostService.Api/PostService.Api.csproj"
RUN dotnet restore PostService/PostService.Api/PostService.Api.csproj

COPY . .

WORKDIR "/src/src/PostService/PostService.Api"
RUN dotnet build -c Release -o /app/build
WORKDIR /src/PostService/PostService.Api

RUN dotnet build PostService.Api.csproj -c Release -o /app/build

FROM build AS publish
RUN dotnet publish -c Release -o /app/publish
RUN dotnet publish PostService.Api.csproj -c Release -o /app/publish

FROM base AS final
WORKDIR /app
Expand Down
Loading