-
Notifications
You must be signed in to change notification settings - Fork 1
119 lines (113 loc) · 3.86 KB
/
push-main.yml
File metadata and controls
119 lines (113 loc) · 3.86 KB
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
name: build, test and deploy
on:
push:
branches:
- main
workflow_dispatch:
jobs:
run_tests_build_app:
name: Run tests and build app
runs-on: ubuntu-20.04
env:
DB_URL: ${{ secrets.DB_URL }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Run Unitary tests
run: mvn -B -Dtest=*Test* test
- name: Run Integration tests
run: mvn -B -Dtest=*IT -Dspring.profiles.active=standalone test
- name: Build native with Maven
run: mvn -B package
- name: Upload jar for next job
uses: actions/upload-artifact@v2
with:
name: target
path: target
retention-days: 1
build_docker_image:
name: Publish in DockerHub
runs-on: ubuntu-20.04
needs: [run_tests_build_app]
env:
IMAGE_NAME: twitter-scheduler-tfm
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Download jar from previous job
uses: actions/download-artifact@v2
with:
name: target
path: target
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
tags: docker-image:latest
outputs: type=docker,dest=/tmp/docker-image.tar
- name: Load Docker image
run: |
docker load --input /tmp/docker-image.tar
- name: Login to DockerHub
run: docker login -u "$DOCKERHUB_USERNAME" -p "$DOCKERHUB_TOKEN"
- name: Push image to DockerHub
run: |
IMAGE_VERSION=$(mvn -q help:evaluate -Dexpression=project.version -DforceStdout)
docker tag docker-image $DOCKERHUB_USERNAME/$IMAGE_NAME:$IMAGE_VERSION
docker tag docker-image $DOCKERHUB_USERNAME/$IMAGE_NAME:latest
docker push $DOCKERHUB_USERNAME/$IMAGE_NAME:$IMAGE_VERSION
docker push $DOCKERHUB_USERNAME/$IMAGE_NAME:latest
build_and_deploy_in_heroku:
name: Publish and deploy in Heroku
runs-on: ubuntu-20.04
needs: [run_tests_build_app]
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Download jar from previous job
uses: actions/download-artifact@v2
with:
name: target
path: target
- name: Heroku Container Registry login
run: heroku container:login
- name: Build and push
run: heroku container:push -a $HEROKU_APP_NAME web
- name: Release
run: heroku container:release -a $HEROKU_APP_NAME web
smoke_tests:
name: Smoke tests
runs-on: ubuntu-20.04
needs: [build_and_deploy_in_heroku]
env:
API_USERNAME: ${{ secrets.API_USERNAME }}
API_PASSWORD: ${{ secrets.API_PASSWORD }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
steps:
- name: Wait app deployment
run: sleep 10
- name: Check app rest api available
uses: wei/curl@v1
with:
args: -u $API_USERNAME:$API_PASSWORD -X GET https://$HEROKU_APP_NAME.herokuapp.com/actuator/health
- name: Check app status is up
run: |
curl -sS https://webinstall.dev/jq | bash
APP_STATUS=$(curl -u $API_USERNAME:$API_PASSWORD -X GET https://$HEROKU_APP_NAME.herokuapp.com/actuator/health | jq '.status' | sed 's/"//g')
echo "APPLICATION STATUS = " $APP_STATUS
if [ "$APP_STATUS" != "UP" ]; then
exit 1
fi