diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml new file mode 100644 index 0000000..f700652 --- /dev/null +++ b/.github/workflows/deploy-dev.yml @@ -0,0 +1,69 @@ +name: Deploy Develop +on: + push: + branches: ["develop"] + pull_request: + branches: ["develop"] + workflow_dispatch: +jobs: + Build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Maven + run: sudo apt-get install -y maven + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: "temurin" + cache: maven + - name: Build with Maven + env: + DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} + DATASOURCE_URL: ${{ secrets.NEON_DATASOURCE_URL }}/${{ secrets.DB_NAME }} + DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} + GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} + GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} + GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} + run: mvn clean install + + deploy: + name: Deploy on Develop + runs-on: self-hosted + needs: Build + steps: + - name: executing remote ssh commands using ssh key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.DEV_HOST }} + username: ${{ secrets.HOSTS_USERNAME }} + key: ${{ secrets.DEV_SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + cd AllConnected/${{ github.event.repository.name }} + echo "Fetching latest code..." + git fetch + git checkout develop + git pull + echo "Building Docker image..." + docker build -t ${{ github.event.repository.name }} . + echo "Creating .env file..." + echo "DATASOURCE_URL=${{ secrets.DEV_DATASOURCE_URL }}/${{ secrets.DB_NAME }}" >> .env + echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env + echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env + docker rm -f ${{ github.event.repository.name }} + docker run --name ${{ github.event.repository.name }} --network all_connected -d -p ${{ secrets.SERVICE_PORT }}:8080 --env-file .env ${{ github.event.repository.name }} + echo "Docker container running..." + rm .env diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml new file mode 100644 index 0000000..7612477 --- /dev/null +++ b/.github/workflows/deploy-qa.yml @@ -0,0 +1,69 @@ +name: Deploy QA +on: + push: + branches: ["release"] + pull_request: + branches: ["release"] + workflow_dispatch: +jobs: + Build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Maven + run: sudo apt-get install -y maven + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: "temurin" + cache: maven + - name: Build with Maven + env: + DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} + DATASOURCE_URL: ${{ secrets.NEON_DATASOURCE_URL }}/${{ secrets.DB_NAME }} + DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} + GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} + GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} + GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} + run: mvn clean install + + Deploy: + name: Deploy on QA + runs-on: self-hosted + needs: Build + steps: + - name: executing remote ssh commands using ssh key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.QA_G2_HOST }} + username: ${{ secrets.HOSTS_USERNAME }} + key: ${{ secrets.QA_G2_SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + cd AllConnected/${{ github.event.repository.name }} + echo "Fetching latest code..." + git fetch + git checkout release + git pull + echo "Building Docker image..." + docker build -t ${{ github.event.repository.name }} . + echo "Creating .env file..." + echo "DATASOURCE_URL=${{ secrets.QA_DATASOURCE_G2_URL }}/${{ secrets.DB_NAME }}" >> .env + echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env + echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env + docker rm -f ${{ github.event.repository.name }} + docker run --name ${{ github.event.repository.name }} --network all_connected -d -p ${{ secrets.SERVICE_PORT }}:8080 --env-file .env ${{ github.event.repository.name }} + echo "Docker container running..." + rm .env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d8ac2ee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Etapa 1: Build +FROM maven:3.9.4-eclipse-temurin-21 AS build + +WORKDIR /app + +# Copiar el pom y código fuente +COPY pom.xml ./ +RUN mvn dependency:go-offline + +COPY src ./src + +RUN mvn clean package -DskipTests + +# Etapa 2: Run +FROM eclipse-temurin:21-jdk-jammy + +WORKDIR /app + +# Copiar el jar generado desde la etapa de build +COPY --from=build /app/target/*.jar app.jar + +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "app.jar"]