Some checks failed
Build And Publish Production Image / Build And Publish Production Image (push) Failing after 16s
72 lines
2.6 KiB
YAML
72 lines
2.6 KiB
YAML
name: Build And Publish Production Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build:
|
|
name: Build And Publish Production Image
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
REGISTRY: gitea.lab:80
|
|
IMAGE_NAME: sancho41/condado-newsletter
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
github-server-url: http://gitea.lab
|
|
|
|
- name: Verify Docker CLI
|
|
run: docker version
|
|
|
|
- name: Log in to Docker Hub (optional)
|
|
if: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }}
|
|
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login docker.io -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
|
|
|
|
- name: Build all-in-one image
|
|
run: docker build -t condado-newsletter:latest -f Dockerfile.allinone .
|
|
|
|
- name: Tag
|
|
run: |
|
|
docker tag condado-newsletter:latest ${REGISTRY}/${IMAGE_NAME}:latest
|
|
docker tag condado-newsletter:latest ${REGISTRY}/${IMAGE_NAME}:${{ github.sha }}
|
|
|
|
- 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 [ -n "$STACK_ID" ]; then
|
|
PAYLOAD=$(jq -n \
|
|
--rawfile stack_file docker-compose.prod.yml \
|
|
'{StackFileContent: $stack_file, Env: [], Prune: false, PullImage: false}')
|
|
|
|
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}')
|
|
|
|
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
|