Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 003cf7e2da | |||
| 6203a83af3 |
@@ -7,78 +7,65 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-java17
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# 1. Checkout the code
|
# 1. Checkout the code
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# 2. Set up Java and Maven
|
# 2. Build the Spring Boot application using the Maven wrapper
|
||||||
- name: Set up JDK (Eclipse Temurin)
|
# (Java 17 is pre-installed in the runner image)
|
||||||
uses: actions/setup-java@v3
|
|
||||||
with:
|
|
||||||
distribution: "temurin"
|
|
||||||
java-version: "17"
|
|
||||||
cache: maven
|
|
||||||
|
|
||||||
# 3. Verify Maven installation
|
|
||||||
- name: Install Maven
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y maven
|
|
||||||
mvn -version
|
|
||||||
|
|
||||||
# 4. Build the Spring Boot application
|
|
||||||
- name: Build Spring Boot Application
|
- name: Build Spring Boot Application
|
||||||
run: |
|
run: ./mvnw clean package -DskipTests
|
||||||
mvn clean package -DskipTests
|
|
||||||
|
|
||||||
# 5. Set up Docker
|
# 3. Derive version tags from the pushed git tag
|
||||||
- name: Set up Docker
|
# e.g. 1.1.0 -> tag_version=1.1.0, minor=1.1, major=1
|
||||||
|
- name: Extract version tags
|
||||||
|
id: ver
|
||||||
run: |
|
run: |
|
||||||
docker --version
|
TAG_VERSION="${{ github.ref_name }}"
|
||||||
|
|
||||||
# 6. Extract the tag name
|
|
||||||
- name: Extract Tag Version
|
|
||||||
id: extract_version
|
|
||||||
run: |
|
|
||||||
TAG_VERSION=$(echo "${GITHUB_REF}" | sed 's#refs/tags/##')
|
|
||||||
if [ -z "$TAG_VERSION" ]; then
|
if [ -z "$TAG_VERSION" ]; then
|
||||||
echo "Error: TAG_VERSION is empty."
|
echo "Error: TAG_VERSION is empty."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_ENV
|
MINOR_VERSION=$(echo "$TAG_VERSION" | cut -d. -f1,2)
|
||||||
|
MAJOR_VERSION=$(echo "$TAG_VERSION" | cut -d. -f1)
|
||||||
|
echo "tag_version=$TAG_VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "minor=$MINOR_VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "major=$MAJOR_VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
# Extract major and minor versions
|
# 4. Set up Docker Buildx (enables layer caching)
|
||||||
MAJOR_VERSION=$(echo "${TAG_VERSION}" | cut -d. -f1)
|
- name: Set up Docker Buildx
|
||||||
MINOR_VERSION=$(echo "${TAG_VERSION}" | cut -d. -f1,2)
|
uses: docker/setup-buildx-action@v3
|
||||||
echo "MAJOR_VERSION=$MAJOR_VERSION" >> $GITHUB_ENV
|
|
||||||
echo "MINOR_VERSION=$MINOR_VERSION" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
# 7. Build the Docker image with the tag
|
# 5. Login to Docker Hub to avoid base-image pull rate limits
|
||||||
- name: Build and Package Docker Image
|
- name: Login to Docker Hub
|
||||||
run: |
|
uses: docker/login-action@v3
|
||||||
docker build -t tea.zendric.de/cedric/xpensely-server:${{ env.TAG_VERSION }} .
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USER }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
# 8. Tag the image with Major Version (e.g., 0)
|
# 6. Login to the Gitea registry
|
||||||
- name: Tag with Major Version
|
|
||||||
run: |
|
|
||||||
docker tag tea.zendric.de/cedric/xpensely-server:${{ env.TAG_VERSION }} tea.zendric.de/cedric/xpensely-server:${{ env.MAJOR_VERSION }}
|
|
||||||
|
|
||||||
# 9. Tag the image with Minor Version (e.g., 0.1)
|
|
||||||
- name: Tag with Minor Version
|
|
||||||
run: |
|
|
||||||
docker tag tea.zendric.de/cedric/xpensely-server:${{ env.TAG_VERSION }} tea.zendric.de/cedric/xpensely-server:${{ env.MINOR_VERSION }}
|
|
||||||
|
|
||||||
# 10. Docker login
|
|
||||||
- name: Login to Docker Registry
|
- name: Login to Docker Registry
|
||||||
run: |
|
uses: docker/login-action@v3
|
||||||
echo "${{ secrets.TEAPASSWORD }}" | docker login tea.zendric.de -u ${{ secrets.TEAUSER }} --password-stdin
|
with:
|
||||||
|
registry: tea.zendric.de
|
||||||
|
username: ${{ secrets.TEAUSER }}
|
||||||
|
password: ${{ secrets.TEAPASSWORD }}
|
||||||
|
|
||||||
# 11. Push the Docker images with the tags
|
# 7. Build and push the versioned Docker images with layer caching.
|
||||||
- name: Push the Docker Image to registry
|
# Pushes exact, minor, and major tags. The prod compose references
|
||||||
run: |
|
# the major tag (":1"), so pushing here makes the new build available
|
||||||
docker push tea.zendric.de/cedric/xpensely-server:${{ env.TAG_VERSION }}
|
# to pull in Dockge — deploy is triggered MANUALLY after the DB migration.
|
||||||
docker push tea.zendric.de/cedric/xpensely-server:${{ env.MAJOR_VERSION }}
|
- name: Build and Push Docker Image
|
||||||
docker push tea.zendric.de/cedric/xpensely-server:${{ env.MINOR_VERSION }}
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
tea.zendric.de/cedric/xpensely-server:${{ steps.ver.outputs.tag_version }}
|
||||||
|
tea.zendric.de/cedric/xpensely-server:${{ steps.ver.outputs.minor }}
|
||||||
|
tea.zendric.de/cedric/xpensely-server:${{ steps.ver.outputs.major }}
|
||||||
|
cache-from: type=registry,ref=tea.zendric.de/cedric/xpensely-server:buildcache
|
||||||
|
cache-to: type=registry,ref=tea.zendric.de/cedric/xpensely-server:buildcache,mode=max
|
||||||
|
|||||||
Reference in New Issue
Block a user