This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Arithmetic Calculator Solution | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: mysql:8 | |
ports: | |
- 3306:3306 | |
env: | |
MYSQL_ROOT_PASSWORD: rootpassword | |
MYSQL_DATABASE: calculator | |
MYSQL_USER: ${{ secrets.DB_USERNAME }} | |
MYSQL_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
options: >- | |
--health-cmd="mysqladmin ping --silent" | |
--health-interval=10s | |
--health-timeout=5s | |
--health-retries=3 | |
volumes: | |
- mysql-data:/var/lib/mysql | |
steps: | |
- name: Cache MySQL Data | |
id: cache-mysql-data | |
uses: actions/cache@v2 | |
with: | |
path: /var/lib/mysql | |
key: mysql-data-${{ github.run_id }} | |
restore-keys: | | |
mysql-data- | |
- name: Checkout Spring Boot Repository | |
uses: actions/checkout@v2 | |
with: | |
repository: encouver/calculator-api | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
- name: Install Maven | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y maven | |
- name: Build with Maven | |
run: | | |
mvn clean install | |
- name: Deploy Spring Boot Application | |
env: | |
SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/calculator | |
SPRING_DATASOURCE_USERNAME: ${{ secrets.DB_USERNAME }} | |
SPRING_DATASOURCE_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
run: | | |
java -jar target/calculator-1.0.0.jar & | |
- name: Trigger React Deployment | |
run: | | |
curl -X POST -H "Authorization: token ${{ secrets.GH_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/encouver/calculator-ui/dispatches \ | |
-d '{"event_type":"deploy"}' |