This repository was archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
83 lines (69 loc) · 2.52 KB
/
Copy pathdocker-image.yml
File metadata and controls
83 lines (69 loc) · 2.52 KB
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
name: "Deploy - api-user-java (Java)"
# run on push to main branch
on:
push:
branches:
- main
paths:
- "apis/user-java/**"
workflow_dispatch:
# Set envs
env:
WORKDIR: "apis/user-java"
DOCKER_IMAGE_BASE_NAME: "devopsoh/api-user-java"
API_NAME: "user-java"
AZURE_WEBAPP_NAME: "devopsoh58998userjava"
# RESOURCES_PREFIX: "devopsoh44707" # hardcoded or dynamic based on repo name
# Set defaults for GitHub Actions runner
defaults:
run:
working-directory: "apis/user-java"
jobs:
build:
name: "Build"
runs-on: ubuntu-latest
outputs:
RESOURCES_PREFIX: ${{ steps.resources_prefix.outputs.result }}
DOCKER_IMAGE_FULL_NAME: ${{ steps.dockerfullname.outputs.DOCKER_IMAGE_FULL_NAME }}
steps:
- uses: actions/checkout@v2
# Get RESOURCES_PREFIX based on the repo name
- name: Get repo name
uses: actions/github-script@v5
id: resources_prefix
with:
result-encoding: string
script: return context.repo.repo.toLowerCase()
# AZURE CONTAINER REGISTRY
- name: Get docker image full name
run: |
DOCKER_IMAGE_FULL_NAME=${{ steps.resources_prefix.outputs.result }}cr.azurecr.io/${{ env.DOCKER_IMAGE_BASE_NAME }}
# Set for current Job
echo "DOCKER_IMAGE_FULL_NAME=${DOCKER_IMAGE_FULL_NAME}" >> ${GITHUB_ENV}
# Set for next Job
echo "::set-output name=DOCKER_IMAGE_FULL_NAME::${DOCKER_IMAGE_FULL_NAME}"
id: dockerfullname
- name: "Azure Login"
uses: Azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: "Build Docker image using Azure Container Registry"
uses: Azure/cli@v1
with:
inlineScript: az acr build --image ${{ env.DOCKER_IMAGE_BASE_NAME }}:${{ github.run_id }} --registry ${{ steps.resources_prefix.outputs.result }}cr.azurecr.io --build-arg build_version=${{ github.run_id }} --file ${{ env.WORKDIR }}/Dockerfile ${{ env.WORKDIR }}
deploy:
permissions:
contents: none
runs-on: ubuntu-latest
needs: build
environment:
name: 'production-user-java'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
images: ${{ env.DOCKER_IMAGE_FULL_NAME }}:${{ github.run_id }}