Skip to content

Commit 322d10b

Browse files
committed
add support for building image with template pulled from source rather than nuget
1 parent f7baefd commit 322d10b

File tree

4 files changed

+77
-46
lines changed

4 files changed

+77
-46
lines changed

.github/workflows/build-and-stage.yml

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ concurrency:
1313

1414
permissions:
1515
contents: read
16-
pull-requests: 'write'
16+
pull-requests: write
1717

1818
env:
1919
IMAGE_NAME: net-core-tool-service
@@ -33,46 +33,55 @@ jobs:
3333
with:
3434
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
3535

36-
- name: Login to Azure
37-
uses: azure/login@v1
38-
with:
39-
creds: ${{ secrets.AZURE_CREDENTIALS }}
36+
- name: Detect template source from PR body
37+
run: |
38+
CheckoutTarget = grep "template_checkout_target=" github.event.pull_request.body | awk '{print $2}'
39+
if [[ $CheckoutTarget ]]; then
40+
echo "Found checkout target '$CheckoutTarget' in PR body, using include templates from source."
41+
echo "{TEMPLATE_CHECKOUT_TARGET}=$CheckoutTarget" >> "$GITHUB_ENV"
42+
else
43+
echo "Did not find a checkout target for templates."
44+
fi
4045
41-
- name: Login to container registry
42-
uses: azure/docker-login@v1
43-
with:
44-
login-server: "${{ vars.DOCKER_REGISTRY }}"
45-
username: "${{ secrets.DOCKER_USERNAME }}"
46-
password: "${{ secrets.DOCKER_PASSWORD }}"
46+
# - name: Login to Azure
47+
# uses: azure/login@v1
48+
# with:
49+
# creds: ${{ secrets.AZURE_CREDENTIALS }}
4750

48-
- name: Build image
49-
run: docker build . --file "Dockerfile" -t ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
51+
# - name: Login to container registry
52+
# uses: azure/docker-login@v1
53+
# with:
54+
# login-server: "${{ vars.DOCKER_REGISTRY }}"
55+
# username: "${{ secrets.DOCKER_USERNAME }}"
56+
# password: "${{ secrets.DOCKER_PASSWORD }}"
5057

51-
- name: Push image
52-
run: docker push ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
58+
# - name: Build image
59+
# run: docker build . -t ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} --build-arg TEMPLATE_CHECKOUT_TARGET=${{ env.TEMPLATE_CHECKOUT_TARGET }}
5360

54-
- name: If PR, create a new staging slot
55-
if: ${{ github.event_name == 'pull_request' }}
56-
run: az webapp deployment slot create --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }} --configuration-source ${{ vars.STAGING_SLOT_NAME }}
61+
# - name: Push image
62+
# run: docker push ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
5763

58-
- name: Deploy to staging slot
59-
uses: azure/webapps-deploy@v3
60-
id: deploy-to-webapp
61-
with:
62-
app-name: ${{ vars.AZURE_WEBAPP_NAME }}
63-
images: ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
64-
slot-name: ${{ env.SLOT_NAME }}
64+
# - name: If PR, create a new staging slot
65+
# if: ${{ github.event_name == 'pull_request' }}
66+
# run: az webapp deployment slot create --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }} --configuration-source ${{ vars.STAGING_SLOT_NAME }}
67+
68+
# - name: Deploy to staging slot
69+
# uses: azure/webapps-deploy@v3
70+
# id: deploy-to-webapp
71+
# with:
72+
# app-name: ${{ vars.AZURE_WEBAPP_NAME }}
73+
# images: ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
74+
# slot-name: ${{ env.SLOT_NAME }}
6575

66-
- name: If PR, comment with the preview link
67-
if: ${{ github.event_name == 'pull_request' }}
68-
uses: mshick/add-pr-comment@v2
69-
with:
70-
message: |
71-
## Preview link: https://${{ vars.AZURE_WEBAPP_NAME }}-${{ env.SLOT_NAME }}.azurewebsites.net
76+
# - name: If PR, comment with the preview link
77+
# if: ${{ github.event_name == 'pull_request' }}
78+
# uses: mshick/add-pr-comment@v2
79+
# with:
80+
# message: |
81+
# ## Preview link: https://${{ vars.AZURE_WEBAPP_NAME }}-${{ env.SLOT_NAME }}.azurewebsites.net
7282

73-
- Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch.
74-
- The preview link is shareable, but will be deleted when the pull request is merged or closed.
83+
# - Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch.
84+
# - The preview link is shareable, but will be deleted when the pull request is merged or closed.
7585

76-
> *This is an automated message.*
77-
repo-token: ${{ secrets.GITHUB_TOKEN }}
78-
86+
# > *This is an automated message.*
87+
# repo-token: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
33
WORKDIR /source
44
COPY . .
5-
RUN dotnet restore
6-
RUN dotnet publish -c release -o /srv --no-restore
5+
RUN dotnet restore src/NetCoreToolService
6+
RUN dotnet build src/NetCoreToolService --configuration Release --no-restore
7+
RUN dotnet publish src/NetCoreToolService --output /srv --no-build
78

89
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine
910
ARG templates_version=1.3.0
10-
#RUN dotnet nuget add source https://pkgs.dev.azure.com/dotnet/Steeltoe/_packaging/dev/nuget/v3/index.json -n SteeltoeDev
11-
RUN dotnet new --install Steeltoe.NetCoreTool.Templates::${templates_version} &&\
12-
dotnet new --list | grep steeltoe-webapi
13-
# WORKDIR /usr/local/src
14-
# RUN git clone https://github.com/SteeltoeOSS/NetCoreToolTemplates
15-
# RUN git -C NetCoreToolTemplates checkout release/1.2
16-
# RUN dotnet new --install NetCoreToolTemplates/src/Content
11+
ARG template_checkout_target
1712
WORKDIR /srv
1813
COPY --from=build /srv .
19-
ENV DOTNET_URLS http://0.0.0.0:80
14+
COPY install-template.sh /srv/install-template.sh
15+
RUN chmod +x /srv/install-template.sh
16+
RUN /srv/install-template.sh
17+
ENV DOTNET_URLS=http://0.0.0.0:80
2018
ENTRYPOINT ["dotnet", "Steeltoe.NetCoreToolService.dll"]

Steeltoe.NetCoreToolService.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,20 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1919
Directory.Build.props = Directory.Build.props
2020
docker-compose.yaml = docker-compose.yaml
2121
Dockerfile = Dockerfile
22+
install-template.sh = install-template.sh
2223
stylecop.json = stylecop.json
2324
Version.props = Version.props
2425
EndProjectSection
2526
EndProject
27+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
28+
EndProject
29+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{4D3C2BC0-3714-42D2-BB89-057E57D92BAF}"
30+
ProjectSection(SolutionItems) = preProject
31+
.github\workflows\build-and-stage.yml = .github\workflows\build-and-stage.yml
32+
.github\workflows\pr-cleanup.yml = .github\workflows\pr-cleanup.yml
33+
.github\workflows\stage-prod-swap.yml = .github\workflows\stage-prod-swap.yml
34+
EndProjectSection
35+
EndProject
2636
Global
2737
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2838
Debug|Any CPU = Debug|Any CPU
@@ -64,6 +74,7 @@ Global
6474
GlobalSection(NestedProjects) = preSolution
6575
{1462EDFE-F1FC-48C2-80C1-917317EE3C97} = {C742A7B8-80CA-4365-85CA-C29AA744CE54}
6676
{6BD6C793-E555-475F-A2E1-12D7F3F56A3B} = {410C0E72-737F-4168-AECA-2F6D19EE86D5}
77+
{4D3C2BC0-3714-42D2-BB89-057E57D92BAF} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
6778
EndGlobalSection
6879
GlobalSection(ExtensibilityGlobals) = postSolution
6980
SolutionGuid = {D8EFB01A-92BF-418B-B2B2-A12045B772E2}

install-template.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env sh
2+
3+
# dotnet nuget add source https://pkgs.dev.azure.com/dotnet/Steeltoe/_packaging/dev/nuget/v3/index.json -n SteeltoeDev
4+
5+
if [[ -z "$TEMPLATE_CHECKOUT_TARGET" ]] ;then
6+
dotnet new install Steeltoe.NetCoreTool.Templates::${templates_version} &&\
7+
dotnet new --list | grep steeltoe-webapi
8+
else
9+
cd /usr/local/src
10+
git clone https://github.com/SteeltoeOSS/NetCoreToolTemplates
11+
git -C NetCoreToolTemplates checkout $TEMPLATE_CHECKOUT_TARGET
12+
dotnet new install NetCoreToolTemplates/src/Content
13+
fi

0 commit comments

Comments
 (0)