Skip to content

Commit

Permalink
Refactored workflow yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakim-Kay committed Jun 14, 2024
1 parent 5056449 commit 1ab7cab
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 43 deletions.
68 changes: 26 additions & 42 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
name: CI

on:
push:
branches:
- main
- test-ci-cd-workflow
pull_request:
branches:
- main
on: [push]

jobs:
build:

runs-on: ubuntu-latest

services:
postgres:
image: postgres:latest
ports:
- "5432:5432"
env:
POSTGRES_DB: acebook_springboot_development
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'adopt'
java-version: '17'

- name: Install Maven
run: sudo apt-get install -y maven

- name: Install dependencies
run: mvn install -DskipTests

- name: Set up Chromedriver
run: |
sudo apt-get install -y wget unzip
wget https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriver

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
Expand All @@ -54,22 +44,16 @@ jobs:
push: true
tags: mhk1/acebook_penguins:latest

- name: Run Docker container
- name: Set up PostgreSQL container
run: |
docker run -d --name acebook_penguins -p 5432:5432 -p 8080:8080 mhk1/acebook_penguins:latest
sleep 30
docker run -d --name acebook_postgres -p 5432:5432 \
-e POSTGRES_DB=acebook_springboot_development \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=password postgres:latest
- name: Run unit tests
run: mvn test -Dtest=PostTest
- name: Wait for PostgreSQL to start
run: sleep 20

- name: Health check
- name: Run Tests
run: |
echo "Waiting for the application to start..."
sleep 30
curl -f http://localhost:8080/login || (docker logs acebook_penguins && exit 1)
- name: Stop Docker container
run: docker stop acebook_penguins

- name: Remove Docker container
run: docker rm acebook_penguins
./mvnw test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ dependency-reduced-pom.xml
.factorypath
.project
.settings/
/src/main/java/com/makersacademy/acebook/config/EnvVariableConfig.java
.DS_STORE
Empty file added docker-compose.yml
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//package com.makersacademy.acebook.config;
//
//import lombok.Getter;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Configuration;
//
//@Getter
//@Configuration
//public class EnvVariableConfig {
//
// // Getter methods to use these values wherever needed
// @Value("${local_password}")
// private String localPassword;
//
// @Value("${local_db}")
// private String localDbUrl;
//
// @Value("${local_db_test}")
// private String local_test_url;
//
//}
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ spring.datasource.username=
spring.datasource.password=
flyway.baseline-on-migrate=true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
4 changes: 4 additions & 0 deletions src/main/resources/application-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ spring.datasource.password=
flyway.baseline-on-migrate=true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect



# jdbc:postgresql://localhost:5432/acebook_springboot_test

0 comments on commit 1ab7cab

Please sign in to comment.