-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (108 loc) · 4 KB
/
build-deploy-all.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
name: Build and Deploy
on:
# push:
# branches:
# - 'dapr'
# - 'dockercompose'
# paths:
# - 'frontend/*'
# - 'catalog/*'
# - 'ordering/*'
# - 'infra/*'
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
set-env:
name: Set Environment Variables
runs-on: ubuntu-latest
outputs:
version: ${{ steps.main.outputs.version }}
created: ${{ steps.main.outputs.created }}
repository: ${{ steps.main.outputs.repository }}
steps:
- id: main
run: |
echo ::set-output name=version::$(echo ${GITHUB_SHA} | cut -c1-7)
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=repository::$GITHUB_REPOSITORY
package-services:
runs-on: ubuntu-latest
needs: set-env
permissions:
contents: read
packages: write
outputs:
containerImage-frontend: ${{ steps.image-tag.outputs.image-frontend }}
containerImage-catalog: ${{ steps.image-tag.outputs.image-catalog }}
containerImage-ordering: ${{ steps.image-tag.outputs.image-ordering }}
strategy:
matrix:
services:
[
{ "appName": "frontend", "directory": "./frontend" },
{ "appName": "catalog", "directory": "./catalog" },
{ "appName": "ordering", "directory": "./ordering" },
]
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN}}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ needs.set-env.outputs.repository }}/${{ matrix.services.appName }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=sha
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
file: "${{ matrix.services.directory }}/Dockerfile"
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Output image tag
id: image-tag
run: |
echo ::set-output name=image-${{ matrix.services.appName }}::${{ env.REGISTRY }}/$GITHUB_REPOSITORY/${{ matrix.services.appName }}:sha-${{ needs.set-env.outputs.version }} | tr '[:upper:]' '[:lower:]'
deploy:
runs-on: ubuntu-latest
needs: [package-services]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_SP }}
- name: Deploy bicep
uses: azure/CLI@v1
with:
inlineScript: |
az deployment group create -g "globo-tickets" -f ./infra/main.bicep \
-p \
frontendImage='${{ needs.package-services.outputs.containerImage-frontend }}' \
catalogImage='${{ needs.package-services.outputs.containerImage-catalog }}' \
orderingImage='${{ needs.package-services.outputs.containerImage-ordering }}' \
containerRegistry=${{ env.REGISTRY }} \
containerRegistryUsername=${{ github.actor }} \
containerRegistryPassword=${{ secrets.GITHUB_TOKEN }} \
appName='globotickets' \