-
Notifications
You must be signed in to change notification settings - Fork 70
49 lines (40 loc) · 1.69 KB
/
docker-image.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
name: Docker Image CI
on: [ workflow_dispatch, pull_request ]
jobs:
buildAndTest:
runs-on: ubuntu-latest
steps:
# Checkout the commit that triggered the workflow
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build --no-cache -t unidata/tomcat-docker:latest .
- name: Download sample wep app
run: |
wget -O $(pwd)/.github/testScripts/sample.war \
https://tomcat.apache.org/tomcat-8.5-doc/appdev/sample/sample.war
- name: Run the container
run: |
docker run --name tomcat \
-e TOMCAT_USER_ID=$(id -u) \
-e TOMCAT_GROUP_ID=$(getent group $USER | cut -d : -f3) \
-v $(pwd)/.github/testScripts:/testScripts \
-v $(pwd)/.github/testScripts:/usr/local/tomcat/webapps \
-d \
-p 8080:8080 \
unidata/tomcat-docker:latest
# Give chance for Tomcat to fire up
- name: Wait and listen for Tomcat to fire up
run: |
nc -z -w300 127.0.0.1 8080
for i in {1..5}; do curl -o /dev/null http://127.0.0.1:8080/sample/index.html && break || \
(echo sleeping 15... && sleep 15); done
- name: Run test script
run: ./.github/testScripts/test.sh
- name: Push to Dockerhub
if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == 'true'}}
run: |
docker logout
echo ${{ secrets.registrypwd }} | docker login -u ${{ secrets.registryuser }} --password-stdin
docker push ${{ secrets.imagename }}:${{ env.tag }} &&
{ docker logout && echo "Successfully pushed ${{ secrets.imagename }}:${{ env.tag }}"; } ||
{ docker logout && echo "Docker push failed" && exit 1; }