Skip to content

Commit

Permalink
package in workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ikwattro committed Aug 27, 2024
1 parent 2629aa2 commit e287f3d
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Push Docker Image
name: Build, Test, and Push Docker Image

on:
push:
Expand All @@ -13,25 +13,45 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin' # Use Eclipse Temurin distribution (AdoptOpenJDK)
java-version: '17'

- name: Log in to Docker Hub
uses: docker/login-action@v2
- name: Cache Maven packages
uses: actions/cache@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven and run tests
run: mvn clean verify

- name: Package the application
run: mvn package -DskipTests

- name: Extract version from pom.xml
id: extract_version
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and tag Docker image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/my-spring-app:${{ env.VERSION }} .
- name: Push Docker image to Docker Hub
run: |
docker push ${{ secrets.DOCKER_USERNAME }}/my-spring-app:${{ env.VERSION }}
docker push ${{ secrets.DOCKER_USERNAME }}/my-spring-app:${{ env.VERSION }}

0 comments on commit e287f3d

Please sign in to comment.