Skip to content

Commit f717229

Browse files
authored
Merge pull request #69 from mystster/changeDeploy
switch to GitHub Container Registry
2 parents b2c8c7b + 5b3c8e6 commit f717229

File tree

3 files changed

+92
-40
lines changed

3 files changed

+92
-40
lines changed

.github/workflows/build_PR.yml

+40-18
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ on:
1414
env:
1515
node-version: 13.10.1
1616
dotnet: 3.1.100
17-
registry: docker.pkg.github.com
18-
repository: mystster/weatherdisp
17+
registry: ghcr.io
1918
image: weatherdisp
2019
functionsApp: WeatherInfo
2120

@@ -61,8 +60,7 @@ jobs:
6160
- name: 'Create Azure functions slot'
6261
if: github.event.action == 'opened' || github.event.action == 'reopened'
6362
run: |
64-
az functionapp deployment slot create --name ${{env.functionsApp}} --slot ${{needs.Prepare.outputs.SLOT_NAME}} --configuration-source stage --resource-group $RESOURCE_GROUP > /dev/null
65-
az functionapp config appsettings set --name ${{env.functionsApp}} --slot ${{needs.Prepare.outputs.SLOT_NAME}} --resource-group $RESOURCE_GROUP --settings "$(az functionapp config appsettings list --name ${{env.functionsApp}} --slot stage --resource-group $RESOURCE_GROUP | jq '[.[] | select(.name=="DARKSKY_API" or .name=="LAG" or .name=="LAT" or .name=="MAX_EXEC")]')" > /dev/null
63+
az functionapp deployment slot create --name ${{env.functionsApp}} --slot ${{needs.Prepare.outputs.SLOT_NAME}} --configuration-source ${{env.functionsApp}} --resource-group $RESOURCE_GROUP > /dev/null
6664
Build_frontend:
6765
name: Build frontend using Vue.
6866
runs-on: ubuntu-latest
@@ -126,6 +124,14 @@ jobs:
126124
steps:
127125
- name: Checkout
128126
uses: actions/checkout@v2
127+
- name: Set up Docker Buildx
128+
uses: docker/setup-buildx-action@v1
129+
- name: Login to GitHub Container Registry
130+
uses: docker/login-action@v1
131+
with:
132+
registry: ${{ env.registry }}
133+
username: ${{ github.repository_owner }}
134+
password: ${{ secrets.CR_PAT }}
129135
- name: Download frontend artifact
130136
uses: actions/download-artifact@v2
131137
with:
@@ -136,17 +142,33 @@ jobs:
136142
with:
137143
name: functions
138144
path: images/artifacts
139-
- name: build image and push to github package registry
140-
uses: docker/build-push-action@v1
145+
- name: Prepare
146+
id: prep
147+
run: |
148+
VERSION=edge
149+
if [[ $GITHUB_REF == refs/tags/* ]]; then
150+
VERSION=${GITHUB_REF#refs/tags/}
151+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
152+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
153+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
154+
VERSION=pr-${{ github.event.number }}
155+
fi
156+
echo ::set-output name=version::${VERSION}
157+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
158+
- name: build image and push to GitHub Container Registry
159+
uses: docker/build-push-action@v2
141160
with:
142-
username: ${{ github.actor }}
143-
password: ${{ secrets.GITHUB_TOKEN }}
144-
repository: ${{ env.repository }}/${{ env.image }}
145-
registry: ${{ env.registry }}
146-
tags: latest, ${{needs.Prepare.outputs.BRANCH}}-latest, ${{needs.Prepare.outputs.TAG_NAME}}
147-
tag_with_ref: true
148-
add_git_labels: true
149-
path: images
161+
push: true
162+
context: images
163+
tags: |
164+
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:latest
165+
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{ steps.prep.outputs.version }}
166+
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{needs.Prepare.outputs.BRANCH}}-latest
167+
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{needs.Prepare.outputs.TAG_NAME}}
168+
labels: |
169+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
170+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
171+
org.opencontainers.image.revision=${{ github.sha }}
150172
151173
DeployPR:
152174
name: Deploy functions container from PR
@@ -155,12 +177,12 @@ jobs:
155177
steps:
156178
- name: checkout
157179
uses: actions/checkout@v2
158-
- name: Github package repositry login
180+
- name: GitHub Container Registry login
159181
uses: azure/docker-login@v1
160182
with:
161183
login-server: ${{ env.registry }}
162-
username: ${{ github.actor }}
163-
password: ${{ secrets.GITHUB_TOKEN }}
184+
username: ${{ github.repository_owner }}
185+
password: ${{ secrets.CR_PAT }}
164186
- name: 'Login via Azure CLI'
165187
uses: azure/login@v1
166188
with:
@@ -170,7 +192,7 @@ jobs:
170192
uses: Azure/functions-container-action@v1
171193
with:
172194
app-name: ${{ env.functionsApp }}
173-
image: ${{ env.registry }}/${{ env.repository }}/${{ env.image }}:${{needs.Prepare.outputs.TAG_NAME}}
195+
image: ${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{needs.Prepare.outputs.TAG_NAME}}
174196
slot-name: ${{needs.Prepare.outputs.SLOT_NAME}}
175197
- name: 'comment access url'
176198
uses: actions/github-script@v1

.github/workflows/build_push.yml

+39-16
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ on:
1414
env:
1515
node-version: 13.10.1
1616
dotnet: 3.1.100
17-
registry: docker.pkg.github.com
18-
repository: mystster/weatherdisp
17+
registry: ghcr.io
1918
image: weatherdisp
2019
functionsApp: WeatherInfo
2120

@@ -156,6 +155,14 @@ jobs:
156155
steps:
157156
- name: Checkout
158157
uses: actions/checkout@v2
158+
- name: Set up Docker Buildx
159+
uses: docker/setup-buildx-action@v1
160+
- name: Login to GitHub Container Registry
161+
uses: docker/login-action@v1
162+
with:
163+
registry: ${{ env.registry }}
164+
username: ${{ github.repository_owner }}
165+
password: ${{ secrets.CR_PAT }}
159166
- name: Download frontend artifact
160167
uses: actions/download-artifact@v2
161168
with:
@@ -166,17 +173,33 @@ jobs:
166173
with:
167174
name: functions
168175
path: images/artifacts
169-
- name: build image and push to github package registry
170-
uses: docker/build-push-action@v1
176+
- name: Prepare
177+
id: prep
178+
run: |
179+
VERSION=edge
180+
if [[ $GITHUB_REF == refs/tags/* ]]; then
181+
VERSION=${GITHUB_REF#refs/tags/}
182+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
183+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
184+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
185+
VERSION=pr-${{ github.event.number }}
186+
fi
187+
echo ::set-output name=version::${VERSION}
188+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
189+
- name: build image and push to GitHub Container Registry
190+
uses: docker/build-push-action@v2
171191
with:
172-
username: ${{ github.actor }}
173-
password: ${{ secrets.GITHUB_TOKEN }}
174-
repository: ${{ env.repository }}/${{ env.image }}
175-
registry: ${{ env.registry }}
176-
tags: latest, ${{needs.Prepare.outputs.BRANCH}}-latest, ${{needs.Prepare.outputs.TAG_NAME}}
177-
tag_with_ref: true
178-
add_git_labels: true
179-
path: images
192+
push: true
193+
context: images
194+
tags: |
195+
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:latest
196+
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{ steps.prep.outputs.version }}
197+
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{needs.Prepare.outputs.BRANCH}}-latest
198+
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{needs.Prepare.outputs.TAG_NAME}}
199+
labels: |
200+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
201+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
202+
org.opencontainers.image.revision=${{ github.sha }}
180203
181204
DeployPush:
182205
name: Deploy functions container from Push
@@ -186,12 +209,12 @@ jobs:
186209
steps:
187210
- name: checkout
188211
uses: actions/checkout@v2
189-
- name: Github package repositry login
212+
- name: GitHub Container Registry login
190213
uses: azure/docker-login@v1
191214
with:
192215
login-server: ${{ env.registry }}
193-
username: ${{ github.actor }}
194-
password: ${{ secrets.GITHUB_TOKEN }}
216+
username: ${{ github.repository_owner }}
217+
password: ${{ secrets.CR_PAT }}
195218
- name: 'Login via Azure CLI'
196219
uses: azure/login@v1
197220
with:
@@ -200,4 +223,4 @@ jobs:
200223
uses: Azure/functions-container-action@v1
201224
with:
202225
app-name: ${{ env.functionsApp }}
203-
image: ${{ env.registry }}/${{ env.repository }}/${{ env.image }}:${{needs.Prepare.outputs.TAG_NAME}}
226+
image: ${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{needs.Prepare.outputs.TAG_NAME}}

Azure/Functions/WeatherDisp/Function1.cs

+13-6
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ public async Task<IActionResult> Run(
3535
return BadRequest();
3636
}
3737

38-
if (int.TryParse(Environment.GetEnvironmentVariable("MAX_EXEC", EnvironmentVariableTarget.Process), out int maxCount)
39-
&& maxCount > 0
40-
&& execCounter <= maxCount)
38+
var slotName = Environment.GetEnvironmentVariable("WEBSITE_SLOT_NAME", EnvironmentVariableTarget.Process);
39+
log.LogInformation($"SlotName:{slotName}");
40+
41+
if(slotName != "Production")
4142
{
42-
model.DarkskyKey = Environment.GetEnvironmentVariable("DARKSKY_API", EnvironmentVariableTarget.Process) ?? model.DarkskyKey;
43-
model.Lag = Environment.GetEnvironmentVariable("LAG", EnvironmentVariableTarget.Process) ?? model.Lag;
44-
model.Lat = Environment.GetEnvironmentVariable("LAT", EnvironmentVariableTarget.Process) ?? model.Lat;
43+
// Slotの設定がある場合は、PR用と想定し、環境変数から情報を収集する
44+
if (int.TryParse(Environment.GetEnvironmentVariable("MAX_EXEC", EnvironmentVariableTarget.Process), out int maxCount)
45+
&& maxCount > 0
46+
&& execCounter <= maxCount)
47+
{
48+
model.DarkskyKey = Environment.GetEnvironmentVariable("DARKSKY_API", EnvironmentVariableTarget.Process) ?? model.DarkskyKey;
49+
model.Lag = Environment.GetEnvironmentVariable("LAG", EnvironmentVariableTarget.Process) ?? model.Lag;
50+
model.Lat = Environment.GetEnvironmentVariable("LAT", EnvironmentVariableTarget.Process) ?? model.Lat;
51+
}
4552
}
4653

4754
if (!TryValidateModel(model))

0 commit comments

Comments
 (0)