docker name removed. #10
This file contains hidden or 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: CI/CD Pipeline # Name of the CI/CD Pipeline | |
| on: | |
| push: | |
| branches: | |
| - main # Trigger on push to the main branch | |
| pull_request: | |
| branches: | |
| - main # Trigger on pull request to the main branch | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest # Runs on the latest version of Ubuntu | Default operating system environment for workflows unless explicitly specified. | |
| steps: | |
| # Checkout code from repository | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| # Set up Oracle JDK 17 | |
| - name: Set up Oracle JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'oracle' # Specify Oracle JDK distribution | |
| # Build the Spring Boot app using Maven | |
| - name: Build Spring Boot App with Maven | |
| run: mvn -f demo/pom.xml clean package | |
| # Login to DockerHub | |
| - name: Log in to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| # Build the Docker image | |
| - name: Build Docker image | |
| run: | | |
| docker build -f demo/Dockerfile -t gowthamdineshrajkumar/demospringboot . | |
| # Push the Docker image to DockerHub | |
| - name: Push the Docker image to DockerHub | |
| run: | | |
| docker push gowthamdineshrajkumar/demospringboot:latest | |
| # Run Docker container in detached mode | |
| - name: Run Docker container locally | |
| run: | | |
| docker run -d -p 8080:8080 --name demospringboot-container gowthamdineshrajkumar/demospringboot:latest | |
| # List running Docker containers (using docker ps) | |
| - name: List running Docker containers | |
| run: | | |
| docker ps | |
| # Print logs from the running container | |
| - name: Print Docker container logs | |
| run: | | |
| echo "Fetching logs from the Docker container..." | |
| docker logs -f demospringboot-container | |
| # Optionally, stop the container after the test | |
| - name: Stop the Docker container | |
| run: | | |
| docker stop demospringboot-container | |
| docker rm demospringboot-container |