-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (118 loc) · 4.52 KB
/
dotnetcore.develop.push.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: .NET Core push on develop branch
on:
push:
branches: [develop]
env:
PROJECT_NAME: MarketplaceService
DOCKER_ORGANIZATION: s652
DOCKER_REPOSITORY: marketplace-service
KUBERNETES_NAMESPACE: s652-develop
jobs:
build:
# The virtual machine that will be used on GitHub
runs-on: ubuntu-18.04
# Run the steps in a Docker container on the virtual machine
container:
image: mcr.microsoft.com/dotnet/core/sdk:3.1.201-bionic
steps:
# Checkout Git repository
- uses: actions/checkout@v2
# Decrypt the gpg encrypted config files
- name: Decrypt the gpg encrypted config files
run: gpg --quiet --batch --yes --passphrase ${{ secrets.GPG_PASSPHRASE }} --output ./${{ env.PROJECT_NAME }}/appsettings.json --decrypt ./${{ env.PROJECT_NAME }}/appsettings.develop.json.gpg
# Install the dependencies needed for the project
- name: Install dependencies
run: dotnet restore
# Build the project
- name: Build
run: dotnet build
# Test the project
- name: Test
run: dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
# Publish the release build in the /release folder
- name: Publish
run: dotnet publish -c Release -o release
# Upload the release folder and Dockerfile artifacts to this GitHub workflow for use in the next job
- name: Upload release artifact
uses: actions/upload-artifact@v1
with:
name: release-artifact
path: ./release
- name: Upload Dockerfile artifact
uses: actions/upload-artifact@v1
with:
name: dockerfile-artifact
path: ./Dockerfile
- name: Upload Kubernetes artifact
uses: actions/upload-artifact@v1
with:
name: kubernetes-artifact
path: ./kube_develop
sonarscanner:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Sonarscanner for dotnet
uses: Secbyte/dotnet-sonarscanner@v2.3
with:
buildCommand: dotnet build .
testCommand: dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
projectKey: S65-2-project_${{ env.PROJECT_NAME }}
projectName: ${{ env.PROJECT_NAME }}
sonarOrganisation: s65-2-project
beginArguments: >
/d:sonar.verbose="true"
/d:sonar.cs.opencover.reportsPaths='"/${{ env.PROJECT_NAME }}Tests/coverage.xml"'
/d:sonar.coverage.exclusions='"**/*.cs","**/*.md","**/sonar-project.properties"'
env:
SONAR_TOKEN: ${{ secrets.SONARCLOUD_ACCESS_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deliver:
needs: build
runs-on: ubuntu-18.04
steps:
# Download artifacts from GitHub workflow to use in this job
- name: Download release artifact
uses: actions/download-artifact@v1
with:
name: release-artifact
path: ./release
- name: Download Dockerfile artifact
uses: actions/download-artifact@v1
with:
name: dockerfile-artifact
path: .
# Deliver Docker image to DockerHub
- name: Deliver Docker image
run: |
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_ACCESS_TOKEN }}
docker build -t ${{ env.DOCKER_ORGANIZATION }}/${{ env.DOCKER_REPOSITORY }}:${{ github.sha }} .
docker push ${{ env.DOCKER_ORGANIZATION }}/${{ env.DOCKER_REPOSITORY }}:${{ github.sha }}
deploy:
needs: deliver
runs-on: ubuntu-18.04
steps:
- name: Download Kubernetes artifact
uses: actions/download-artifact@v1
with:
name: kubernetes-artifact
path: ./kube_develop
- name: Setup Kubectl
uses: azure/setup-kubectl@v1
- name: Set context via kubeconfig
uses: azure/k8s-set-context@v1
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBE_CONFIG }}
- name: Deploy Kubernetes with manifests
uses: azure/k8s-deploy@v1
with:
namespace: ${{ env.KUBERNETES_NAMESPACE }}
manifests: |
./kube_develop/autoscaler.yaml
./kube_develop/cluster-issuer.yaml
./kube_develop/deployment.yaml
./kube_develop/ingress.yaml
./kube_develop/service.yaml
images: |
${{ env.DOCKER_ORGANIZATION }}/${{ env.DOCKER_REPOSITORY }}:${{ github.sha }}