fix: streamline deployment process by removing Gitea registry login steps and enhancing Portainer API integration
Some checks failed
Build And Publish Production Image / Build And Publish Production Image (push) Failing after 16s

This commit is contained in:
2026-03-28 02:21:36 -03:00
parent cb74fdef7b
commit 4fd90b2497

View File

@@ -33,25 +33,39 @@ jobs:
run: |
docker tag condado-newsletter:latest ${REGISTRY}/${IMAGE_NAME}:latest
docker tag condado-newsletter:latest ${REGISTRY}/${IMAGE_NAME}:${{ github.sha }}
# - name: Log in to Gitea container registry
# run: |
# if [ -z "$REGISTRY_USERNAME" ]; then
# REGISTRY_USERNAME="${{ github.actor }}"
# echo "REGISTRY_USERNAME secret is empty; falling back to github.actor: $REGISTRY_USERNAME"
# fi
- name: Deploy stack via Portainer API
env:
STACK_NAME: condado-newsletter
PORTAINER_URL: http://portainer.lab
PORTAINER_API_KEY: ${{ secrets.PORTAINER_API_KEY }}
PORTAINER_ENDPOINT_ID: ${{ secrets.PORTAINER_ENDPOINT_ID }}
run: |
STACK_ID=$(curl -sf \
"${PORTAINER_URL}/api/stacks" \
-H "X-API-Key: ${PORTAINER_API_KEY}" \
| jq -r --arg stack_name "$STACK_NAME" '.[] | select(.Name == $stack_name) | .Id' \
| head -n 1)
# if [ -z "$REGISTRY_PASSWORD" ]; then
# echo "REGISTRY_PASSWORD secret is empty; cannot log in to ${REGISTRY}."
# exit 1
# fi
if [ -n "$STACK_ID" ]; then
PAYLOAD=$(jq -n \
--rawfile stack_file docker-compose.prod.yml \
'{StackFileContent: $stack_file, Env: [], Prune: false, PullImage: false}')
# echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY" -u "$REGISTRY_USERNAME" --password-stdin
curl -sf -X PUT \
"${PORTAINER_URL}/api/stacks/${STACK_ID}?endpointId=${PORTAINER_ENDPOINT_ID}" \
-H "X-API-Key: ${PORTAINER_API_KEY}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"
else
PAYLOAD=$(jq -n \
--arg name "$STACK_NAME" \
--rawfile stack_file docker-compose.prod.yml \
'{Name: $name, StackFileContent: $stack_file, Env: [], FromAppTemplate: false}')
# - name: Tag and push registry images
# run: |
# docker tag condado-newsletter:latest ${REGISTRY}/${IMAGE_NAME}:latest
# docker tag condado-newsletter:latest ${REGISTRY}/${IMAGE_NAME}:${{ github.sha }}
# docker push ${REGISTRY}/${IMAGE_NAME}:latest
# docker push ${REGISTRY}/${IMAGE_NAME}:${{ github.sha }}
curl -sf -X POST \
"${PORTAINER_URL}/api/stacks/create/standalone/string?endpointId=${PORTAINER_ENDPOINT_ID}" \
-H "X-API-Key: ${PORTAINER_API_KEY}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"
fi