Skip to content

Commit

Permalink
fix: Build - Docker image workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Bailonis committed Nov 16, 2023
1 parent 98d51d2 commit 3ea3d9a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 121 deletions.
70 changes: 36 additions & 34 deletions .github/workflows/build-master-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@
# ********************************************************************************


name: build-and-push-image-backend
name: Build - Docker image (SemVer)

on:
push:
paths:
- 'demand-capacity-mgmt-backend/**'
- 'demand-capacity-mgmt-specification/**'
branches:
- 'main'
- main
tags:
- 'v*.*.*'
- 'v*.*.*-*'
pull_request:
branches:
- main

env:
IMAGE_NAME: 'demand-capacity-mgmt-backend'
REGISTRY: 'docker.io'
IMAGE_NAMESPACE: 'tractusx'


Expand All @@ -49,46 +48,49 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

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

- name: Run Tests
run: ./demand-capacity-mgmt-backend/mvnw -B test

- name: Build
run: mvn -B package

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ .env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Create SemVer or ref tags dependent of trigger event
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.REGISTRY }}/${{ github.repository }}/${{ env.IMAGE_NAME }}
${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}
# Automatically prepare image tags; See action docs for more examples.
# semver patter will generate tags like these for example :1 :1.2 :1.2.3
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver ,pattern={{major}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push Docker image
uses: docker/build-push-action@v4
- name: DockerHub login
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
# Use existing DockerHub credentials present as secrets
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./build/backend/Dockerfile
#push: ${{ github.event_name != 'pull_request' }}
push: true
# build tag :latest
tags: ${{ steps.meta.outputs.tags }}, ${{ .env.REGISTRY }}/${{ github.repository }}/${{ .env.IMAGE_NAME }}:latest
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ steps.meta.outputs.tags }},
${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}


# https://github.com/peter-evans/dockerhub-description
# Important step to push image description to DockerHub
- name: Update Docker Hub description
if: github.event_name != 'pull_request'
uses: peter-evans/dockerhub-description@v3
with:
# readme-filepath defaults to toplevel README.md, Only necessary if you have a dedicated file with your 'Notice for docker images'
readme-filepath: DOCKER_NOTICE.md
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
repository: ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}
87 changes: 0 additions & 87 deletions .github/workflows/build-master-frontend.yml

This file was deleted.

0 comments on commit 3ea3d9a

Please sign in to comment.