diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml deleted file mode 100644 index 71fa30b..0000000 --- a/.gitea/workflows/ci.yaml +++ /dev/null @@ -1,33 +0,0 @@ -name: CI / Build -on: - push: - branches: - - main - pull_request: - -jobs: - build-and-test: - runs-on: ubuntu-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Set up Node.js for API - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install API Dependencies - working-directory: ./api - run: npm install - - - name: Install Frontend Dependencies - working-directory: ./frontend - run: npm install - - - name: Run Backend Syntax Check - working-directory: ./api - run: node -c server.js - - - name: CI Completed Successfully - run: echo "🎉 Build and checks passed successfully!" diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..25d66b9 --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,45 @@ +name: CI/CD Pipeline +on: + push: + branches: + - main + paths-ignore: + - 'api-deployment.yaml' + - 'frontend-deployment.yaml' + +jobs: + build-push-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Log in to Gitea Container Registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login gitea-http.gitea.svc.cluster.local:3000 -u ${{ github.actor }} --password-stdin + + - name: Build and Push API + run: | + docker build -t gitea-http.gitea.svc.cluster.local:3000/${{ github.repository_owner }}/tamagotchi-api:${{ github.sha }} ./api + docker push gitea-http.gitea.svc.cluster.local:3000/${{ github.repository_owner }}/tamagotchi-api:${{ github.sha }} + + - name: Build and Push Frontend + run: | + docker build -t gitea-http.gitea.svc.cluster.local:3000/${{ github.repository_owner }}/tamagotchi-frontend:${{ github.sha }} ./frontend + docker push gitea-http.gitea.svc.cluster.local:3000/${{ github.repository_owner }}/tamagotchi-frontend:${{ github.sha }} + + - name: Update Kubernetes Manifests + run: | + sed -i "s|image: .*tamagotchi-api:.*|image: gitea-http.gitea.svc.cluster.local:3000/${{ github.repository_owner }}/tamagotchi-api:${{ github.sha }}|g" api-deployment.yaml + sed -i "s|image: .*tamagotchi-frontend:.*|image: gitea-http.gitea.svc.cluster.local:3000/${{ github.repository_owner }}/tamagotchi-frontend:${{ github.sha }}|g" frontend-deployment.yaml + + - name: Commit and Push changes + run: | + git config --global user.name "gitea-actions[bot]" + git config --global user.email "gitea-actions@gitea.local" + # Set the origin URL with the token to allow pushing back + git remote set-url origin http://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@gitea-http.gitea.svc.cluster.local:3000/${{ github.repository }} + git add api-deployment.yaml frontend-deployment.yaml + git commit -m "chore: deploy version ${{ github.sha }} [skip ci]" || echo "No changes to commit" + git push origin main