104 lines
2.9 KiB
YAML
104 lines
2.9 KiB
YAML
name: production-orders-sync CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
DEFAULT_REGISTRY_URL: gitea.blyzer.com.br
|
|
DEFAULT_IMAGE_REPOSITORY: blyzer/production-order-tiny
|
|
|
|
jobs:
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "22"
|
|
cache: npm
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Run tests
|
|
run: npm test
|
|
|
|
- name: Run syntax checks
|
|
run: npm run check
|
|
|
|
build-and-push:
|
|
name: Build and Push Image
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- test
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Resolve image names
|
|
env:
|
|
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
|
|
IMAGE_REPOSITORY: ${{ secrets.IMAGE_REPOSITORY }}
|
|
run: |
|
|
set -eu
|
|
REGISTRY_URL="${REGISTRY_URL:-$DEFAULT_REGISTRY_URL}"
|
|
IMAGE_REPOSITORY="${IMAGE_REPOSITORY:-$DEFAULT_IMAGE_REPOSITORY}"
|
|
SHORT_SHA="$(printf '%s' "$GITHUB_SHA" | cut -c1-12)"
|
|
IMAGE_REF="${REGISTRY_URL}/${IMAGE_REPOSITORY}"
|
|
|
|
echo "REGISTRY_URL=${REGISTRY_URL}" >> "$GITHUB_ENV"
|
|
echo "IMAGE_REF=${IMAGE_REF}" >> "$GITHUB_ENV"
|
|
echo "IMAGE_TAG=${SHORT_SHA}" >> "$GITHUB_ENV"
|
|
echo "Building ${IMAGE_REF}:${SHORT_SHA} and ${IMAGE_REF}:latest"
|
|
|
|
- name: Login to registry
|
|
env:
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
run: |
|
|
set -eu
|
|
if [ -z "${REGISTRY_USERNAME:-}" ] || [ -z "${REGISTRY_TOKEN:-}" ]; then
|
|
echo "REGISTRY_USERNAME and REGISTRY_TOKEN secrets are required."
|
|
exit 1
|
|
fi
|
|
printf '%s' "$REGISTRY_TOKEN" | docker login "$REGISTRY_URL" --username "$REGISTRY_USERNAME" --password-stdin
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
set -eu
|
|
docker build --pull \
|
|
--tag "${IMAGE_REF}:${IMAGE_TAG}" \
|
|
--tag "${IMAGE_REF}:latest" \
|
|
.
|
|
|
|
- name: Push Docker image
|
|
run: |
|
|
set -eu
|
|
docker push "${IMAGE_REF}:${IMAGE_TAG}"
|
|
docker push "${IMAGE_REF}:latest"
|
|
|
|
deploy-portainer:
|
|
name: Trigger Portainer
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- build-and-push
|
|
steps:
|
|
- name: Trigger Portainer stack webhook
|
|
env:
|
|
PORTAINER_WEBHOOK_URL: ${{ secrets.PORTAINER_WEBHOOK_URL }}
|
|
run: |
|
|
set -eu
|
|
if [ -z "${PORTAINER_WEBHOOK_URL:-}" ]; then
|
|
echo "PORTAINER_WEBHOOK_URL secret is not set; skipping Portainer trigger."
|
|
exit 0
|
|
fi
|
|
curl --fail --silent --show-error --request POST "$PORTAINER_WEBHOOK_URL"
|
|
echo "Portainer webhook triggered."
|