From ae5b90f2c429c926d7d01c7c3da12dba2818acab Mon Sep 17 00:00:00 2001 From: Eduard Kuksa Date: Sun, 23 Feb 2025 16:24:52 +0700 Subject: [PATCH] add builad and deploy gitea pipeline --- .gitea/workflows/main.yml | 93 +++++++++++++++++++++++++++++++++++++++ Dockerfile | 6 +++ docker-compose.yml | 10 +++++ pom.xml | 6 +-- 4 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 .gitea/workflows/main.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml new file mode 100644 index 0000000..4795023 --- /dev/null +++ b/.gitea/workflows/main.yml @@ -0,0 +1,93 @@ +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: searchengine-artifact + path: | + target/*.jar + Dockerfile + docker-compose.yml + + - name: Create Maven settings.xml + run: | + cat < ~/.m2/settings.xml + + + + gitea + ${{ vars.OWNER }} + ${{ secrets.ACCESS_TOKEN }} + + + + 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: searchengine-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: Create Directory on Local Server + run: ssh -T ${{ vars.DEPLOY_USER }}@${{ vars.DEPLOY_HOST }} mkdir -p ${{ vars.DEPLOY_PATH }} + + - name: Deploy to Local Server + run: scp -r artifact/* ${{ vars.DEPLOY_USER }}@${{ vars.DEPLOY_HOST }}:${{ vars.DEPLOY_PATH }} + + - name: Create .env file on Local Server + run: | + ssh -T ${{ vars.DEPLOY_USER }}@${{ vars.DEPLOY_HOST }} << EOF + echo "DB_USER=${{ vars.DB_USER }}" > ${{ vars.DEPLOY_PATH }}/.env + echo "DB_PASSWORD=${{ vars.DB_PASSWORD }}" >> ${{ vars.DEPLOY_PATH }}/.env + echo "DB_URL=${{ vars.DB_URL }}" >> ${{ vars.DEPLOY_PATH }}/.env + EOF + + - 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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..65e2bee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM openjdk:21-jdk-slim +WORKDIR /app +COPY target/searchengine-*.jar ./searchengine.jar +COPY .env ./ +EXPOSE 8080 +CMD ["java", "-jar", "searchengine.jar"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..29f1df7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile + image: searchengine + container_name: searchengine + ports: + - "8090:8080" + restart: always \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4f2ca58..8040576 100644 --- a/pom.xml +++ b/pom.xml @@ -6,11 +6,11 @@ dev.kuksa searchengine - 1.0-SNAPSHOT + 0.0.1-SNAPSHOT - 23 - 23 + 21 + 21 UTF-8