Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Further improvements with git commit version (add support for docker image)

support11a8f39b9745
diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml
index c66ab796c..ea734a2e5 100644
--- a/.github/workflows/docker-image.yml
+++ b/.github/workflows/docker-image.yml
@@ -1,5 +1,8 @@
name: Docker Image CI
+env:
+ TAG: 'latest'
+
on:
push:
branches: [ "master" ]
@@ -16,25 +19,20 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- - id: Commit
- name: Commit-tag
- uses: pr-mpt/actions-commit-hash@v2
- name: Buildx
id: buildx
uses: docker/setup-buildx-action@v1
-
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASS }}
-
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
build-args: |
- GIT_COMMIT=${{ steps.commit.outputs.long }}
- GIT_BRANCH=master
+ GIT_COMMIT=${{ github.sha }}
+ GIT_BRANCH=${{ github.ref_name }}
push: true
- tags: grandnode/grandnode2:latest
\ No newline at end of file
+ tags: grandnode/grandnode2:${{ env.TAG }}
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index 5cee47667..ea4a4fee9 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -25,8 +25,14 @@ RUN dotnet build /app/Plugins/Widgets.FacebookPixel -c Release -p:SourceRevision
RUN dotnet build /app/Plugins/Widgets.GoogleAnalytics -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
RUN dotnet build /app/Plugins/Widgets.Slider -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
-# build Web
-RUN dotnet publish /app/Web/Grand.Web -c Release -o ./build/release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+# restore
+RUN dotnet restore /app/Web/Grand.Web/Grand.Web.csproj
+
+#build
+RUN dotnet build /app/Web/Grand.Web/Grand.Web.csproj --no-restore -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+
+# publish Web
+RUN dotnet publish /app/Web/Grand.Web --no-restore -c Release -o ./build/release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
diff --git a/src/Build/Grand.Common.props b/src/Build/Grand.Common.props
index b124f24ba..23c183798 100644
--- a/src/Build/Grand.Common.props
+++ b/src/Build/Grand.Common.props
@@ -18,17 +18,20 @@
<Using Include="System.Threading"/>
<Using Include="System.Threading.Tasks"/>
</ItemGroup>
- <Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
+ <Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation" Condition="'$(SourceRevisionId)'==''">
<Exec Command="git describe --long --always --exclude=* --abbrev=8" ConsoleToMSBuild="True" IgnoreExitCode="True">
<Output PropertyName="SourceRevisionId" TaskParameter="ConsoleOutput" />
</Exec>
</Target>
- <Target Name="SetRepositoryBranch" BeforeTargets="InitializeSourceControlInformation">
+ <Target Name="SetRepositoryBranch" BeforeTargets="InitializeSourceControlInformation" Condition="'$(GitBranch)'==''">
<Exec Command="git rev-parse --abbrev-ref HEAD" ConsoleToMSBuild="True" IgnoreExitCode="True">
- <Output PropertyName="GitBranch" TaskParameter="ConsoleOutput" />
+ <Output PropertyName="branch" TaskParameter="ConsoleOutput" />
</Exec>
<ItemGroup>
- <AssemblyMetadata Include="BranchName" Value="$(GitBranch)" />
+ <AssemblyMetadata Include="BranchName" Value="$(branch)" />
</ItemGroup>
</Target>
+ <ItemGroup Condition="'$(GitBranch)'!=''">
+ <AssemblyMetadata Include="GitBranch" Value="$(GitBranch)" />
+ </ItemGroup>
</Project>
diff --git a/src/Core/Grand.Infrastructure/GrandVersion.cs b/src/Core/Grand.Infrastructure/GrandVersion.cs
index 36ca00a6d..79d94f58a 100644
--- a/src/Core/Grand.Infrastructure/GrandVersion.cs
+++ b/src/Core/Grand.Infrastructure/GrandVersion.cs
@@ -68,7 +68,7 @@ namespace Grand.Infrastructure
var appAssembly = typeof(GrandVersion).Assembly;
var infoBranchAttr = appAssembly.GetCustomAttributes(typeof(AssemblyMetadataAttribute))
- .FirstOrDefault(x => ((AssemblyMetadataAttribute)x).Key == "BranchName");
+ .FirstOrDefault(x => ((AssemblyMetadataAttribute)x).Key == "GitBranch");
_gitBranch = infoBranchAttr != null ? ((AssemblyMetadataAttribute)infoBranchAttr).Value : "UNKNOWN";
return _gitBranch;
}