Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit e57a97d

Browse files
Update workflows to use composite (#1753)
* Update workflows to use composite * Add name to composite actions * Revert name change
1 parent 464b8fc commit e57a97d

31 files changed

+525
-1173
lines changed

.github/workflows/basket-api-deploy.yml

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,12 @@ jobs:
2424
steps:
2525
- uses: actions/checkout@v2
2626

27-
- uses: azure/login@v1
27+
- uses: ./.github/workflows/composite/deploy-helm
2828
with:
29-
creds: ${{ secrets.AZURE_CREDENTIALS }}
30-
31-
- uses: azure/aks-set-context@v1
32-
name: Set AKS context
33-
with:
34-
creds: '${{ secrets.AZURE_CREDENTIALS }}'
35-
cluster-name: ${{ secrets.CLUSTER_NAME }}
36-
resource-group: ${{ secrets.RESOURCE_GROUP }}
37-
38-
- name: Set branch name as env variable
39-
run: |
40-
currentbranch=$(echo ${GITHUB_REF##*/})
41-
echo "running on $currentbranch"
42-
echo "BRANCH=$currentbranch" >> $GITHUB_ENV
43-
shell: bash
44-
45-
- name: Deploy Chart
46-
run: |
47-
./deploy-chart.sh -c ${{ env.CHART }} --dns aks --aks-name ${{ secrets.CLUSTER_NAME }} --aks-rg ${{ secrets.RESOURCE_GROUP }} -r ${{ secrets.REGISTRY_HOST }} -t $TAG --namespace ${{ env.NAMESPACE }} --acr-connected
48-
env:
49-
TAG: ${{ env.BRANCH }}
50-
working-directory: ${{ env.CHART_ROOT }}
29+
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
30+
cluster_name: ${{ secrets.CLUSTER_NAME }}
31+
resource_group: ${{ secrets.RESOURCE_GROUP }}
32+
registry_host: ${{ secrets.REGISTRY_HOST }}
33+
chart: ${{ env.CHART }}
34+
chart_root: ${{ env.CHART_ROOT }}
35+
namespace: ${{ env.NAMESPACE }}

.github/workflows/basket-api.yml

Lines changed: 14 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -22,105 +22,31 @@ on:
2222
env:
2323
SERVICE: basket-api
2424
IMAGE: basket.api
25-
DOTNET_VERSION: 5.0.x
2625

2726
jobs:
2827

2928
BuildContainersForPR_Linux:
3029
runs-on: ubuntu-latest
3130
if: ${{ github.event_name == 'pull_request' }}
3231
steps:
33-
- name: 'Checkout Github Action'
34-
uses: actions/checkout@master
35-
36-
- name: Setup dotnet
37-
uses: actions/setup-dotnet@v1
32+
- name: Checkout code
33+
uses: actions/checkout@v2
34+
- uses: ./.github/workflows/composite/build
3835
with:
39-
dotnet-version: ${{ env.DOTNET_VERSION }}
40-
41-
- name: Build and run unit tests
42-
run: |
43-
cd src
44-
dotnet restore "eShopOnContainers-ServicesAndWebApps.sln"
45-
cd Services/Basket/Basket.API
46-
dotnet build --no-restore
47-
cd -
48-
cd Services/Basket/Basket.UnitTests
49-
dotnet build --no-restore
50-
dotnet test --no-build -v=normal
51-
52-
- name: Compose build ${{ env.SERVICE }}
53-
run: sudo -E docker-compose build ${{ env.SERVICE }}
54-
working-directory: ./src
55-
shell: bash
56-
env:
57-
TAG: ${{ env.BRANCH }}
58-
REGISTRY: ${{ secrets.REGISTRY_ENDPOINT }}
36+
service: ${{ env.SERVICE }}
37+
registry_endpoint: ${{ secrets.REGISTRY_ENDPOINT }}
5938

6039
BuildLinux:
6140
runs-on: ubuntu-latest
6241
if: ${{ github.event_name != 'pull_request' }}
6342
steps:
64-
- name: 'Checkout Github Action'
65-
uses: actions/checkout@master
66-
67-
- name: Setup dotnet
68-
uses: actions/setup-dotnet@v1
43+
- name: Checkout code
44+
uses: actions/checkout@v2
45+
- uses: ./.github/workflows/composite/build-push
6946
with:
70-
dotnet-version: ${{ env.DOTNET_VERSION }}
71-
72-
- name: Build and run unit tests
73-
run: |
74-
cd src
75-
dotnet restore "eShopOnContainers-ServicesAndWebApps.sln"
76-
cd Services/Basket/Basket.API
77-
dotnet build --no-restore
78-
cd -
79-
cd Services/Basket/Basket.UnitTests
80-
dotnet build --no-restore
81-
dotnet test --no-build -v=normal
82-
83-
- name: Enable experimental features for the Docker daemon and CLI
84-
run: |
85-
echo $'{\n "experimental": true\n}' | sudo tee /etc/docker/daemon.json
86-
mkdir -p ~/.docker
87-
echo $'{\n "experimental": "enabled"\n}' | sudo tee ~/.docker/config.json
88-
sudo service docker restart
89-
docker version -f '{{.Client.Experimental}}'
90-
docker version -f '{{.Server.Experimental}}'
91-
92-
- name: Login to Container Registry
93-
uses: docker/login-action@v1
94-
with:
95-
registry: ${{ secrets.REGISTRY_HOST }}
96-
username: ${{ secrets.USERNAME }}
97-
password: ${{ secrets.PASSWORD }}
98-
99-
- name: Set branch name as env variable
100-
run: |
101-
currentbranch=$(echo ${GITHUB_REF##*/})
102-
echo "running on $currentbranch"
103-
echo "BRANCH=$currentbranch" >> $GITHUB_ENV
104-
shell: bash
105-
106-
- name: Compose build ${{ env.SERVICE }}
107-
run: sudo -E docker-compose build ${{ env.SERVICE }}
108-
working-directory: ./src
109-
shell: bash
110-
env:
111-
TAG: ${{ env.BRANCH }}
112-
REGISTRY: ${{ secrets.REGISTRY_ENDPOINT }}
113-
114-
- name: Compose push ${{ env.SERVICE }}
115-
run: sudo -E docker-compose push ${{ env.SERVICE }}
116-
working-directory: ./src
117-
shell: bash
118-
env:
119-
TAG: ${{ env.BRANCH }}
120-
REGISTRY: ${{ secrets.REGISTRY_ENDPOINT }}
121-
122-
- name: Create multiarch manifest
123-
run: |
124-
docker --config ~/.docker manifest create ${{ secrets.REGISTRY_ENDPOINT }}/${{ env.IMAGE }}:${{ env.BRANCH }} ${{ secrets.REGISTRY_ENDPOINT }}/${{ env.IMAGE }}:linux-${{ env.BRANCH }}
125-
docker --config ~/.docker manifest push ${{ secrets.REGISTRY_ENDPOINT }}/${{ env.IMAGE }}:${{ env.BRANCH }}
126-
shell: bash
47+
service: ${{ env.SERVICE }}
48+
registry_host: ${{ secrets.REGISTRY_HOST }}
49+
registry_endpoint: ${{ secrets.REGISTRY_ENDPOINT }}
50+
image_name: ${{ env.IMAGE }}
51+
registry_username: ${{ secrets.USERNAME }}
52+
registry_password: ${{ secrets.PASSWORD }}

.github/workflows/catalog-api-deploy.yml

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,12 @@ jobs:
2424
steps:
2525
- uses: actions/checkout@v2
2626

27-
- uses: azure/login@v1
27+
- uses: ./.github/workflows/composite/deploy-helm
2828
with:
29-
creds: ${{ secrets.AZURE_CREDENTIALS }}
30-
31-
- uses: azure/aks-set-context@v1
32-
name: Set AKS context
33-
with:
34-
creds: '${{ secrets.AZURE_CREDENTIALS }}'
35-
cluster-name: ${{ secrets.CLUSTER_NAME }}
36-
resource-group: ${{ secrets.RESOURCE_GROUP }}
37-
38-
- name: Set branch name as env variable
39-
run: |
40-
currentbranch=$(echo ${GITHUB_REF##*/})
41-
echo "running on $currentbranch"
42-
echo "BRANCH=$currentbranch" >> $GITHUB_ENV
43-
shell: bash
44-
45-
- name: Deploy chart
46-
run: |
47-
./deploy-chart.sh -c ${{ env.CHART }} --dns aks --aks-name ${{ secrets.CLUSTER_NAME }} --aks-rg ${{ secrets.RESOURCE_GROUP }} -r ${{ secrets.REGISTRY_HOST }} -t $TAG --namespace ${{ env.NAMESPACE }} --acr-connected
48-
env:
49-
TAG: ${{ env.BRANCH }}
50-
working-directory: ${{ env.CHART_ROOT }}
29+
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
30+
cluster_name: ${{ secrets.CLUSTER_NAME }}
31+
resource_group: ${{ secrets.RESOURCE_GROUP }}
32+
registry_host: ${{ secrets.REGISTRY_HOST }}
33+
chart: ${{ env.CHART }}
34+
chart_root: ${{ env.CHART_ROOT }}
35+
namespace: ${{ env.NAMESPACE }}

.github/workflows/catalog-api.yml

Lines changed: 19 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -23,104 +23,36 @@ env:
2323
SERVICE: catalog-api
2424
IMAGE: catalog.api
2525
DOTNET_VERSION: 5.0.x
26+
PROJECT_PATH: Services/Catalog/Catalog.API
27+
TESTS_PATH: Services/Catalog/Catalog.UnitTests
2628

2729
jobs:
2830

2931
BuildContainersForPR_Linux:
3032
runs-on: ubuntu-latest
3133
if: ${{ github.event_name == 'pull_request' }}
3234
steps:
33-
- name: 'Checkout Github Action'
34-
uses: actions/checkout@master
35-
36-
- name: Setup dotnet
37-
uses: actions/setup-dotnet@v1
35+
- name: Checkout code
36+
uses: actions/checkout@v2
37+
- uses: ./.github/workflows/composite/build-test
3838
with:
39-
dotnet-version: ${{ env.DOTNET_VERSION }}
40-
41-
- name: Build and run unit tests
42-
run: |
43-
cd src
44-
dotnet restore "eShopOnContainers-ServicesAndWebApps.sln"
45-
cd Services/Catalog/Catalog.API
46-
dotnet build --no-restore
47-
cd -
48-
cd Services/Catalog/Catalog.UnitTests
49-
dotnet build --no-restore
50-
dotnet test --no-build -v=normal
51-
52-
- name: Compose build ${{ env.SERVICE }}
53-
run: sudo -E docker-compose build ${{ env.SERVICE }}
54-
working-directory: ./src
55-
shell: bash
56-
env:
57-
TAG: ${{ env.BRANCH }}
58-
REGISTRY: ${{ secrets.REGISTRY_ENDPOINT }}
39+
service: ${{ env.SERVICE }}
40+
registry_endpoint: ${{ secrets.REGISTRY_ENDPOINT }}
41+
dotnet_version: ${{ env.DOTNET_VERSION }}
42+
project_path: ${{ env.PROJECT_PATH }}
43+
tests_path: ${{ env.TESTS_PATH }}
5944

6045
BuildLinux:
6146
runs-on: ubuntu-latest
6247
if: ${{ github.event_name != 'pull_request' }}
6348
steps:
64-
- name: 'Checkout Github Action'
65-
uses: actions/checkout@master
66-
67-
- name: Setup dotnet
68-
uses: actions/setup-dotnet@v1
49+
- name: Checkout code
50+
uses: actions/checkout@v2
51+
- uses: ./.github/workflows/composite/build-push
6952
with:
70-
dotnet-version: ${{ env.DOTNET_VERSION }}
71-
72-
- name: Build and run unit tests
73-
run: |
74-
cd src
75-
dotnet restore "eShopOnContainers-ServicesAndWebApps.sln"
76-
cd Services/Catalog/Catalog.API
77-
dotnet build --no-restore
78-
cd -
79-
cd Services/Catalog/Catalog.UnitTests
80-
dotnet build --no-restore
81-
dotnet test --no-build -v=normal
82-
83-
- name: Enable experimental features for the Docker daemon and CLI
84-
run: |
85-
echo $'{\n "experimental": true\n}' | sudo tee /etc/docker/daemon.json
86-
mkdir -p ~/.docker
87-
echo $'{\n "experimental": "enabled"\n}' | sudo tee ~/.docker/config.json
88-
sudo service docker restart
89-
docker version -f '{{.Client.Experimental}}'
90-
docker version -f '{{.Server.Experimental}}'
91-
92-
- name: Login to Container Registry
93-
uses: docker/login-action@v1
94-
with:
95-
registry: ${{ secrets.REGISTRY_HOST }}
96-
username: ${{ secrets.USERNAME }}
97-
password: ${{ secrets.PASSWORD }}
98-
99-
- name: Set branch name as env variable
100-
run: |
101-
currentbranch=$(echo ${GITHUB_REF##*/})
102-
echo "running on $currentbranch"
103-
echo "BRANCH=$currentbranch" >> $GITHUB_ENV
104-
shell: bash
105-
106-
- name: Compose build ${{ env.SERVICE }}
107-
run: sudo -E docker-compose build ${{ env.SERVICE }}
108-
working-directory: ./src
109-
shell: bash
110-
env:
111-
TAG: ${{ env.BRANCH }}
112-
REGISTRY: ${{ secrets.REGISTRY_ENDPOINT }}
113-
114-
- name: Compose push ${{ env.SERVICE }}
115-
run: sudo -E docker-compose push ${{ env.SERVICE }}
116-
working-directory: ./src
117-
shell: bash
118-
env:
119-
TAG: ${{ env.BRANCH }}
120-
REGISTRY: ${{ secrets.REGISTRY_ENDPOINT }}
121-
122-
- name: Create multiarch manifest
123-
run: |
124-
docker --config ~/.docker manifest create ${{ secrets.REGISTRY_ENDPOINT }}/${{ env.IMAGE }}:${{ env.BRANCH }} ${{ secrets.REGISTRY_ENDPOINT }}/${{ env.IMAGE }}:linux-${{ env.BRANCH }}
125-
docker --config ~/.docker manifest push ${{ secrets.REGISTRY_ENDPOINT }}/${{ env.IMAGE }}:${{ env.BRANCH }}
126-
shell: bash
53+
service: ${{ env.SERVICE }}
54+
registry_host: ${{ secrets.REGISTRY_HOST }}
55+
registry_endpoint: ${{ secrets.REGISTRY_ENDPOINT }}
56+
image_name: ${{ env.IMAGE }}
57+
registry_username: ${{ secrets.USERNAME }}
58+
registry_password: ${{ secrets.PASSWORD }}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: "Build and push image"
2+
description: "Builds and pushes an image to a registry"
3+
4+
inputs:
5+
service:
6+
description: "Service to build"
7+
required: true
8+
registry_host:
9+
description: "Image registry host e.g. myacr.azureacr.io"
10+
required: true
11+
registry_endpoint:
12+
description: "Image registry repo e.g. myacr.azureacr.io/eshop"
13+
required: true
14+
image_name:
15+
description: "Name of image"
16+
required: true
17+
registry_username:
18+
description: "Registry username"
19+
required: true
20+
registry_password:
21+
description: "Registry password"
22+
required: true
23+
24+
runs:
25+
using: "composite"
26+
steps:
27+
- name: Enable experimental features for the Docker daemon and CLI
28+
shell: bash
29+
run: |
30+
echo $'{\n "experimental": true\n}' | sudo tee /etc/docker/daemon.json
31+
mkdir -p ~/.docker
32+
echo $'{\n "experimental": "enabled"\n}' | sudo tee ~/.docker/config.json
33+
sudo service docker restart
34+
docker version -f '{{.Client.Experimental}}'
35+
docker version -f '{{.Server.Experimental}}'
36+
37+
- name: Login to Container Registry
38+
uses: docker/login-action@v1
39+
with:
40+
registry: ${{ inputs.registry_host }}
41+
username: ${{ inputs.registry_username }}
42+
password: ${{ inputs.registry_password }}
43+
44+
- name: Set branch name as env variable
45+
run: |
46+
currentbranch=$(echo ${GITHUB_REF##*/})
47+
echo "running on $currentbranch"
48+
echo "BRANCH=$currentbranch" >> $GITHUB_ENV
49+
shell: bash
50+
51+
- name: Compose build ${{ inputs.service }}
52+
shell: bash
53+
run: sudo -E docker-compose build ${{ inputs.service }}
54+
working-directory: ./src
55+
env:
56+
TAG: ${{ env.BRANCH }}
57+
REGISTRY: ${{ inputs.registry_endpoint }}
58+
59+
- name: Compose push ${{ inputs.service }}
60+
shell: bash
61+
run: sudo -E docker-compose push ${{ inputs.service }}
62+
working-directory: ./src
63+
env:
64+
TAG: ${{ env.BRANCH }}
65+
REGISTRY: ${{ inputs.registry_endpoint }}
66+
67+
- name: Create multiarch manifest
68+
shell: bash
69+
run: |
70+
docker --config ~/.docker manifest create ${{ inputs.registry_endpoint }}/${{ inputs.image_name }}:${{ env.BRANCH }} ${{ inputs.registry_endpoint }}/${{ inputs.image_name }}:linux-${{ env.BRANCH }}
71+
docker --config ~/.docker manifest push ${{ inputs.registry_endpoint }}/${{ inputs.image_name }}:${{ env.BRANCH }}

0 commit comments

Comments
 (0)