On my home server installed Gitea and Gitea action runner in docker. I created a pipeline for a java application, the code of which is placed in Gitea repository, the application is built without problems. Here is the pipeline code:
name: Gitea Action Maven build
`on:` ` push:` ` branches: ['testbranch']`
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Set up Maven
uses: stCarolas/setup-maven@v5
with:
maven-version: '3.9.9'
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'oracle'
cache: 'maven'
- name: Build with Maven
run: mvn -B package --file pom.xml
But now the questions - where can I find the assembled jar in Gitea? And how can I deploy and run the assembled application in docker on my home server?
The problem has been successfully solved.
Nice! <3 Maybe you could share how you solved it?
Akito
February 12, 2025, 4:34pm
4
How’d you solve it?
…
…
…
edkuksa
February 13, 2025, 4:48pm
5
Of course, sorry for the slight delay. To solve the issue, I wrote a small pipeline and docker files, the code is below:
maven.yml
name: Gitea Action Maven build
on:
push:
branches: ['master']
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Set up Maven
uses: stCarolas/setup-maven@v5
with:
maven-version: 3.9.9
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'oracle'
cache: 'maven'
- name: Build, Test and Package with Maven
run: mvn -B verify --file pom.xml -e
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: app-artifact
path: |
target/*.jar
Dockerfile
docker-compose.yml
- name: Create Maven settings.xml
run: |
cat <<EOF > ~/.m2/settings.xml
<settings>
<servers>
<server>
<id>gitea</id>
<username>${{ vars.OWNER }}</username>
<password>${{ secrets.ACCESS_TOKEN }}</password>
</server>
</servers>
</settings>
EOF
- name: Replace {owner} in pom.xml
run: sed -i "s/{owner}/${{ vars.OWNER }}/g" pom.xml
- name: Deploy to Gitea Packages
run: mvn deploy
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: app-artifact
path: artifact
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: Deploy to Local Server
run: scp -r artifact/* ${{ vars.DEPLOY_USER }}@${{ vars.DEPLOY_HOST }}:${{ vars.DEPLOY_PATH }}
- name: Build and Run Docker Image with Docker Compose
run: |
ssh -T ${{ vars.DEPLOY_USER }}@${{ vars.DEPLOY_HOST }} << EOF
cd ${{ vars.DEPLOY_PATH }}
docker compose down
docker compose up -d --build
EOF
Dockerfile
FROM openjdk:21-jdk-slim
WORKDIR /app
COPY target/spring-app-*.jar spring-app.jar
EXPOSE 8080
CMD ["java", "-jar", "spring-app.jar"]
docker-compose.yml
services:
app:
build:
context: .
dockerfile: Dockerfile
image: spring-app
container_name: spring-app
ports:
- "8080:8080"
restart: always
fragment of the pom.xml
<repositories>
<repository>
<id>gitea</id>
<url>https://git.example.com/api/packages/{owner}/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitea</id>
<url>https://git.example.com/api/packages/{owner}/maven</url>
</repository>
<snapshotRepository>
<id>gitea</id>
<url>https://git.example.com/api/packages/{owner}/maven</url>
</snapshotRepository>
</distributionManagement>
1 Like