Merge pull request 'Refactored CI workflows: removed auto-tag.yml, merged tagging logic into build.yml. Added app version management in Dockerfile and pom.xml.' (#29) from fix/versiontagging into main
Reviewed-on: #29
This commit is contained in:
commit
6c2e32005f
3 changed files with 85 additions and 17 deletions
|
|
@ -1,12 +1,10 @@
|
||||||
name: Build and Push Docker Image
|
name: Build, Tag and Push Docker Image
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- dev
|
- dev
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
@ -18,6 +16,61 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Determine version and create tag (main only)
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
if [ "${{ gitea.ref_name }}" = "main" ]; then
|
||||||
|
# Hole letzten Tag
|
||||||
|
LATEST_TAG=$(git tag -l "v*" --sort=-v:refname | head -n 1)
|
||||||
|
|
||||||
|
if [ -z "$LATEST_TAG" ]; then
|
||||||
|
NEW_TAG="v1.0.0"
|
||||||
|
BUMP="minor"
|
||||||
|
else
|
||||||
|
VERSION=${LATEST_TAG#v}
|
||||||
|
MAJOR=$(echo $VERSION | cut -d. -f1)
|
||||||
|
MINOR=$(echo $VERSION | cut -d. -f2)
|
||||||
|
PATCH=$(echo $VERSION | cut -d. -f3)
|
||||||
|
|
||||||
|
COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"%s" 2>/dev/null || echo "")
|
||||||
|
|
||||||
|
if [ -z "$COMMITS" ]; then
|
||||||
|
echo "Keine neuen Commits seit ${LATEST_TAG}"
|
||||||
|
echo "skip=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if echo "$COMMITS" | grep -qiE "^BREAKING CHANGE:|^[^:]+!:|breaking:|major:"; then
|
||||||
|
MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0; BUMP="major"
|
||||||
|
elif echo "$COMMITS" | grep -qiE "^feat:|^feature:|minor:"; then
|
||||||
|
MINOR=$((MINOR + 1)); PATCH=0; BUMP="minor"
|
||||||
|
else
|
||||||
|
PATCH=$((PATCH + 1)); BUMP="patch"
|
||||||
|
fi
|
||||||
|
|
||||||
|
NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Prüfe ob Tag bereits existiert
|
||||||
|
if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then
|
||||||
|
echo "Tag ${NEW_TAG} existiert bereits"
|
||||||
|
echo "skip=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "version=${NEW_TAG#v}" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "Erstelle neues Tag: ${NEW_TAG} (${BUMP})"
|
||||||
|
echo "new_tag=${NEW_TAG}" >> $GITHUB_OUTPUT
|
||||||
|
echo "version=${NEW_TAG#v}" >> $GITHUB_OUTPUT
|
||||||
|
echo "skip=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Dev branch: snapshot version
|
||||||
|
echo "version=dev-${{ gitea.sha }}" >> $GITHUB_OUTPUT
|
||||||
|
echo "skip=true" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Login to Gitea Container Registry
|
- name: Login to Gitea Container Registry
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -27,8 +80,8 @@ jobs:
|
||||||
id: tags
|
id: tags
|
||||||
run: |
|
run: |
|
||||||
IMAGE_BASE="git.avatic.de/lcc_public/lcc"
|
IMAGE_BASE="git.avatic.de/lcc_public/lcc"
|
||||||
TAGS=""
|
VERSION="${{ steps.version.outputs.version }}"
|
||||||
|
TAGS="-t ${IMAGE_BASE}:${VERSION}"
|
||||||
TAGS="${TAGS} -t ${IMAGE_BASE}:${{ gitea.sha }}"
|
TAGS="${TAGS} -t ${IMAGE_BASE}:${{ gitea.sha }}"
|
||||||
|
|
||||||
if [ "${{ gitea.ref_name }}" = "main" ]; then
|
if [ "${{ gitea.ref_name }}" = "main" ]; then
|
||||||
|
|
@ -38,11 +91,6 @@ jobs:
|
||||||
TAGS="${TAGS} -t ${IMAGE_BASE}:dev"
|
TAGS="${TAGS} -t ${IMAGE_BASE}:dev"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${{ gitea.ref }}" == refs/tags/* ]]; then
|
|
||||||
VERSION="${{ gitea.ref_name }}"
|
|
||||||
TAGS="${TAGS} -t ${IMAGE_BASE}:${VERSION}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
|
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
|
||||||
echo "image_base=${IMAGE_BASE}" >> $GITHUB_OUTPUT
|
echo "image_base=${IMAGE_BASE}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
|
@ -50,13 +98,16 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
docker build \
|
docker build \
|
||||||
--build-arg BUILDKIT_INLINE_CACHE=1 \
|
--build-arg BUILDKIT_INLINE_CACHE=1 \
|
||||||
|
--build-arg APP_VERSION=${{ steps.version.outputs.version }} \
|
||||||
${{ steps.tags.outputs.tags }} \
|
${{ steps.tags.outputs.tags }} \
|
||||||
.
|
.
|
||||||
|
|
||||||
- name: Push Docker images
|
- name: Push Docker images
|
||||||
run: |
|
run: |
|
||||||
IMAGE_BASE="${{ steps.tags.outputs.image_base }}"
|
IMAGE_BASE="${{ steps.tags.outputs.image_base }}"
|
||||||
|
VERSION="${{ steps.version.outputs.version }}"
|
||||||
|
|
||||||
|
docker push ${IMAGE_BASE}:${VERSION}
|
||||||
docker push ${IMAGE_BASE}:${{ gitea.sha }}
|
docker push ${IMAGE_BASE}:${{ gitea.sha }}
|
||||||
|
|
||||||
if [ "${{ gitea.ref_name }}" = "main" ]; then
|
if [ "${{ gitea.ref_name }}" = "main" ]; then
|
||||||
|
|
@ -66,12 +117,16 @@ jobs:
|
||||||
docker push ${IMAGE_BASE}:dev
|
docker push ${IMAGE_BASE}:dev
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${{ gitea.ref }}" == refs/tags/* ]]; then
|
- name: Create and push git tag
|
||||||
docker push ${IMAGE_BASE}:${{ gitea.ref_name }}
|
if: gitea.ref_name == 'main' && steps.version.outputs.skip != 'true' && steps.version.outputs.new_tag != ''
|
||||||
fi
|
run: |
|
||||||
|
git config user.name "Gitea Actions"
|
||||||
|
git config user.email "actions@gitea.local"
|
||||||
|
git tag -a ${{ steps.version.outputs.new_tag }} -m "Release ${{ steps.version.outputs.new_tag }}"
|
||||||
|
git push origin ${{ steps.version.outputs.new_tag }}
|
||||||
|
|
||||||
- name: Deploy to Docker
|
- name: Deploy to Docker
|
||||||
if: github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev')
|
if: gitea.event_name == 'push' && (gitea.ref_name == 'main' || gitea.ref_name == 'dev')
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy_key
|
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy_key
|
||||||
|
|
|
||||||
12
dockerfile
12
dockerfile
|
|
@ -7,14 +7,22 @@ RUN npm run build
|
||||||
|
|
||||||
FROM maven:3.9-eclipse-temurin-23 AS backend-build
|
FROM maven:3.9-eclipse-temurin-23 AS backend-build
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
ARG APP_VERSION=0.0.1-SNAPSHOT
|
||||||
|
|
||||||
COPY pom.xml ./
|
COPY pom.xml ./
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
# copy frontend
|
|
||||||
COPY --from=frontend-build /app/frontend/dist ./src/main/resources/static
|
COPY --from=frontend-build /app/frontend/dist ./src/main/resources/static
|
||||||
RUN mvn clean package -DskipTests
|
RUN mvn versions:set -DnewVersion=${APP_VERSION} -DgenerateBackupPoms=false && \
|
||||||
|
mvn clean package -DskipTests
|
||||||
|
|
||||||
FROM eclipse-temurin:23-jre-alpine
|
FROM eclipse-temurin:23-jre-alpine
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
ARG APP_VERSION=0.0.1-SNAPSHOT
|
||||||
|
ENV APP_VERSION=${APP_VERSION}
|
||||||
|
LABEL version="${APP_VERSION}"
|
||||||
|
|
||||||
COPY --from=backend-build /app/target/*.jar app.jar
|
COPY --from=backend-build /app/target/*.jar app.jar
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
ENTRYPOINT ["java", "-jar", "app.jar"]
|
ENTRYPOINT ["java", "-jar", "app.jar"]
|
||||||
5
pom.xml
5
pom.xml
|
|
@ -209,6 +209,11 @@
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>versions-maven-plugin</artifactId>
|
||||||
|
<version>2.18.0</version>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jvnet.jaxb</groupId>
|
<groupId>org.jvnet.jaxb</groupId>
|
||||||
<artifactId>jaxb-maven-plugin</artifactId>
|
<artifactId>jaxb-maven-plugin</artifactId>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue