forked from USACE/cwms-data-api
-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (169 loc) · 6.06 KB
/
build.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---
name: Build CWMS Data API
on:
push:
branches:
- develop
- 'release/**'
pull_request:
branches:
- develop
jobs:
build:
name: build and test
runs-on: ubuntu-latest
outputs:
thewar: ${{steps.thebuild.outputs.WARFILE}}
steps:
- name: checkout code
uses: actions/checkout@v2
- name: setup java
uses: actions/setup-java@v1
with:
java-version: '8'
java-package: jdk
- name: build and test
id: thebuild
run: ./gradlew build --info --init-script init.gradle
- name: Upload WAR
uses: actions/upload-artifact@v2
with:
name: warfile
path: cwms-data-api/build/libs/${{steps.thebuild.outputs.WARFILE}}
retention-days: 1
if-no-files-found: error
- name: Build docker image
run: docker build -t cda:build-latest .
release:
if: github.event_name == 'push' && startsWith(github.ref,'refs/heads/release')
name: Create and push releases
needs: build
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v2
- name: setup java
uses: actions/setup-java@v1
with:
java-version: '8'
java-package: jdk
- name: Download all workflow run artifacts from build
id: artifacts
uses: actions/download-artifact@v2
with:
path: ./
- name: get version
id: get_version
run: .github/workflows/get_version.sh
- name: show version
run: echo ${VERSION}
- name: tag repo
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{env.VERSION}}",
sha: context.sha
})
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN }}
with:
tag_name: ${{env.VERSION}}
release_name: Release ${{env.VERSION}}
- name: Upload Tomcat War
id: upload-war
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: warfile/${{ needs.build.outputs.thewar}}
asset_name: ${{ env.WAR_FILE_NAME}}
asset_content_type: application/x-webarchive
- name: Login to Alt Registry
uses: docker/login-action@v2.0.0
id: login-alt
with:
registry: ${{ secrets.ALT_REGISTRY }}
username: ${{ secrets.ALT_REG_USER }}
password: ${{ secrets.ALT_REG_PASSWORD }}
- name: Build docker image
env:
IMAGE_TAG: ${{env.VERSION}}
ALT_REGISTRY: ${{secrets.ALT_REGISTRY}}
run: |
docker build -t cda:build-latest .
docker tag cda:build-latest $ALT_REGISTRY/cwms/data-api:$IMAGE_TAG
docker tag cda:build-latest $ALT_REGISTRY/cwms/data-api:latest
docker push $ALT_REGISTRY/cwms/data-api:$IMAGE_TAG
docker push $ALT_REGISTRY/cwms/data-api:latest
- name: Logout of ALT registry
if: ${{ always() }}
run: docker logout ${{ steps.login-alt.outputs.registry }}
publish:
if: github.event_name == 'push' && startsWith(github.ref,'refs/heads/develop')
name: API Container Image
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: build
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkout code
uses: actions/checkout@v2
- name: setup java
uses: actions/setup-java@v1
with:
java-version: '8'
java-package: jdk
- name: get Data-API version
id: get_version
run: .github/workflows/get_version.sh
- name: Configure AWS credentials
if: ${{ always() }}
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.CWBICI_DEVELOP_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CWBICI_DEVELOP_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.CWBICI_DEVELOP_AWS_REGION }}
- name: Login to Amazon ECR
if: ${{ success() }}
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Login to Alt Registry
uses: docker/login-action@v2.0.0
id: login-alt
with:
registry: ${{ secrets.ALT_REGISTRY }}
username: ${{ secrets.ALT_REG_USER }}
password: ${{ secrets.ALT_REG_PASSWORD }}
- name: Build, tag, and push image to Amazon ECR (cwms/data-api)
if: ${{ success() }}
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
# do not change to cwms-data-api; upstream config also requires change
ECR_REPOSITORY: cwms-radar-api
IMAGE_TAG: ${{env.VERSION}}
ALT_REGISTRY: ${{ secrets.ALT_REGISTRY }}
run: |
docker build -t cda:build-latest .
docker tag cda:build-latest $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker tag cda:build-latest $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker tag cda:build-latest $ALT_REGISTRY/cwms/data-api:$IMAGE_TAG
docker tag cda:build-latest $ALT_REGISTRY/cwms/data-api:latest-dev
docker push $ALT_REGISTRY/cwms/data-api:$IMAGE_TAG
docker push $ALT_REGISTRY/cwms/data-api:latest-dev
- name: Logout of Amazon ECR
if: ${{ always() }}
run: docker logout ${{ steps.login-ecr.outputs.registry }}
- name: Logout of ALT registry
if: ${{ always() }}
run: docker logout ${{ steps.login-alt.outputs.registry }}