name: CI/CD Pipeline on: push: branches: [main] jobs: deploy: name: Build & Deploy runs-on: ubuntu-latest steps: - name: Clone repo run: | git clone --depth=1 --branch=main https://gitlab.impresion3d.pro/root/davidaragon-portfolio.git repo cd repo && ls -la - name: Build image with docker run: | cd repo docker build -t gitlab.impresion3d.pro/root/davidaragon-portfolio:latest . - name: Login to registry run: | echo "${{ secrets.DOCKER_PASSWORD }}" | docker login gitlab.impresion3d.pro -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin - name: Push image run: | docker push gitlab.impresion3d.pro/root/davidaragon-portfolio:latest - name: Stop Portainer stack run: | curl -X POST "${{ secrets.PORTAINER_URL }}/api/stacks/${{ secrets.PORTAINER_STACK_ID }}/stop?endpointId=${{ secrets.PORTAINER_ENDPOINT_ID }}" \ -H "X-API-Key: ${{ secrets.PORTAINER_TOKEN }}" sleep 5 - name: Pull fresh image run: | curl -X POST "${{ secrets.PORTAINER_URL }}/api/endpoints/${{ secrets.PORTAINER_ENDPOINT_ID }}/docker/images/create?fromImage=gitlab.impresion3d.pro%2Froot%2Fdavidaragon-portfolio&tag=latest" \ -H "X-API-Key: ${{ secrets.PORTAINER_TOKEN }}" - name: Start Portainer stack run: | curl -X POST "${{ secrets.PORTAINER_URL }}/api/stacks/${{ secrets.PORTAINER_STACK_ID }}/start?endpointId=${{ secrets.PORTAINER_ENDPOINT_ID }}" \ -H "X-API-Key: ${{ secrets.PORTAINER_TOKEN }}"