-
Notifications
You must be signed in to change notification settings - Fork 2
134 lines (130 loc) · 4.37 KB
/
deploy-app.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
name: Publish docker image, push into the catalog and update the deployed application
# Uncommment this to launch the workflow manually.
#on: workflow_dispatch
on:
push:
branches: [main]
env:
PLAYGROUND_PAT: ${{ secrets.PLAYGROUND_PAT}}
PLAYGROUND_ACCOUNT_NAME: napptive # TODO: Change with your Playground account name.
TARGET_DOCKER_REGISTRY: napptive # TODO: Change this with your docker account name.
jobs:
build:
name: Push docker images
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Docker Login
uses: docker/login-action@v1
with:
username: ${{secrets.DOCKER_HUB_USER}}
password: ${{secrets.DOCKER_HUB_TOKEN}}
- name: Build and push Docker images
run: make docker-push
- name: Render Kubernetes OAM files
run: make k8s
# Create a cache with the generated files
- name: Uploading manifest
id: cache-k8s
uses: actions/cache@v2
with:
key: k8s-yaml-${{ github.sha }}
path: ./build/*
check-app:
needs: build
name: Check if the app are deployed
runs-on: ubuntu-latest
outputs:
not-found: ${{ steps.not-found.outputs.not-found }}
found: ${{ steps.found.outputs.found }}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Check if the app exists
uses: napptive-actions/playground-github-action@v2.2.4
continue-on-error: true
id: check
with:
cmd: "apps info cd-example"
- name: Set App not found
id: not-found
run: echo '::set-output name=not-found::true'
if: steps.check.outcome != 'success'
- name: Set App found
id: found
run: echo '::set-output name=found::true'
if: steps.check.outcome != 'failure'
push-to-catalog:
needs: build
name: Push the application to the catalog
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get k8sfiles
uses: actions/cache@v2
id: cache-k8s
with:
path: ./build/*
key: k8s-yaml-${{ github.sha }}
- name: Get Version
id: version
run: echo "::set-output name=version::$(cat version)"
- name: Push the application on the catalog
uses: napptive-actions/catalog-push-action@v2.2.4
with:
applicationPath: ./build/k8s/
namespace: ${{ env.PLAYGROUND_ACCOUNT_NAME }}
applicationName: "cd-example"
tag: ${{ steps.version.outputs.version }}
update-app:
name: Update application
needs: check-app
runs-on: ubuntu-latest
# if the application aready exists -> update it
if: ${{needs.check-app.outputs.found == 'true'}}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get k8sfiles
uses: actions/cache@v2
id: cache-k8s
with:
path: ./build/
key: k8s-yaml-${{ github.sha }}
- name: Make scripts executable
run: chmod +x ./scripts/*.sh
- name: Get Kubeconfig
uses: napptive-actions/playground-github-action@v2.2.4
with:
cmd: "get-kubeconfig"
- name: Get Version
id: version
run: echo "::set-output name=version::$(cat version)"
- name: Deploy new version of the application
run: ./scripts/update.sh
env:
VERSION: ${{ steps.version.outputs.version }}
deploy-app:
name: Deploy application from catalog
needs: [check-app, push-to-catalog]
runs-on: ubuntu-latest
if: ${{needs.check-app.outputs.not-found == 'true'}}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get Version
id: get-version
run: echo "::set-output name=version::$(cat version)"
- name: Set catalog qualified application name
id: appname
run: echo "::set-output name=appname::${PLAYGROUND_ACCOUNT_NAME}/cd-example:${{ steps.get-version.outputs.version }}"
- name: Deploy the app from the catalog
uses: napptive-actions/catalog-deploy-action@v2.2.4
with:
appName: ${{ steps.appname.outputs.appname }}