-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (134 loc) · 4.55 KB
/
docker-image.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
141
142
143
144
145
146
147
148
149
150
151
name: Build and Deploy From A2B API
on:
pull_request:
branches:
- main
- develop
types: [opened, closed, synchronize]
release:
types: [published]
env:
aspnet_Core: Production
jobs:
setup_tag:
name: Setup dockerTag
runs-on: ubuntu-latest
outputs:
docker_tag: ${{ steps.setup_docker_tag.outputs.DockerTag }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup dockerTag
id: setup_docker_tag
run: |
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.action }}" != "closed" ]]; then
case "${{ github.base_ref }}" in
"develop")
echo "::set-output name=DockerTag::dev-pr"
;;
"main")
echo "::set-output name=DockerTag::main-pr"
;;
esac
else
case "${{ github.ref }}" in
"refs/heads/develop")
echo "::set-output name=DockerTag::dev"
;;
"refs/heads/main")
echo "::set-output name=DockerTag::rc"
;;
"refs/tags/*")
echo "::set-output name=DockerTag::release"
;;
esac
fi
restore_build:
name: Restore and Build Project
runs-on: ubuntu-latest
outputs:
artifact_path: ${{ steps.build.outputs.artifact_path }}
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET 8.0 SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.x.x
- name: Cache .NET packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-dotnet-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-dotnet-
- name: App Settings Variable Substitution Global
uses: microsoft/variable-substitution@v1
with:
files: './Map.Api/appsettings.json'
env:
JWTSettings.Secret: ${{secrets.JWT_KEY}}
MailSettings.Server: ${{secrets.MAIL_SERVER}}
MailSettings.Port: ${{secrets.MAIL_PORT}}
MailSettings.UserName: ${{secrets.MAIL_USERNAME}}
MailSettings.Password: ${{secrets.MAIL_PASSWORD}}
- name: Restore dependencies
run: dotnet restore ./Map.Api/Map.API.csproj
- name: Build project
id: build
env:
USE_IN_MEMORY_DATABASE: 'true'
run: |
mkdir -p build
dotnet build ./Map.Api/Map.API.csproj --configuration Release --output ./build
- name: Archive compiled files
uses: actions/upload-artifact@v2
with:
name: compiled-files
path: ./build/*
CI:
name: Building and deploy Image from-a2b-api
runs-on: ubuntu-latest
needs:
- setup_tag
- restore_build
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download compiled files artifact
uses: actions/download-artifact@v2
with:
name: compiled-files
path: ./compiled-files
- name: DockerHub login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build Docker Image
run: docker buildx build --platform linux/amd64,linux/arm --file ./Map.Api/Dockerfile.Release --tag ${{ secrets.REGISTRY_NAME }}/from-a2b-api:${{ needs.setup_tag.outputs.docker_tag }} --push ./compiled-files
CD:
name: Update Portainer Service
runs-on: ubuntu-latest
needs: CI
if: ${{ needs.CI.result == 'success' }}
steps:
- name: Send POST request to Portainer webhook
run: |
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.action }}" == "closed" ]]; then
case "${{ github.ref }}" in
"refs/heads/develop")
curl -X POST -H "Content-Type: application/json" -d '{}' ${{ secrets.FROMA2B_PORTAINER_WEBHOOK_API_DEV }}
;;
"refs/heads/main")
curl -X POST -H "Content-Type: application/json" -d '{}' ${{ secrets.FROMA2B_PORTAINER_WEBHOOK_STAGING }}
;;
"refs/tags/*")
curl -X POST -H "Content-Type: application/json" -d '{}' ${{ secrets.FROMA2B_PORTAINER_WEBHOOK_API_RELEASE }}
;;
esac
fi