63 lines
2.0 KiB
YAML
63 lines
2.0 KiB
YAML
name: sampleapp-cicd
|
|
|
|
on:
|
|
push:
|
|
branches: ["**"]
|
|
pull_request:
|
|
|
|
jobs:
|
|
ci:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
REGISTRY: gitea.tests01.helity.org
|
|
IMAGE: gitea.tests01.helity.org/lab/sampleapp
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Lint / validate content
|
|
run: |
|
|
set -e
|
|
test -f index.html
|
|
test -f Dockerfile
|
|
grep -q "<title>" index.html
|
|
grep -q "FROM nginx" Dockerfile
|
|
echo "lint OK"
|
|
|
|
- name: Inject commit SHA into page
|
|
run: |
|
|
set -e
|
|
sed -i "s/__GIT_SHA__/${GITHUB_SHA}/g" index.html
|
|
grep -q "${GITHUB_SHA}" index.html && echo "sha injected: ${GITHUB_SHA}"
|
|
|
|
- name: Build image
|
|
run: |
|
|
set -e
|
|
docker build -t "${IMAGE}:${GITHUB_SHA}" -t "${IMAGE}:latest" .
|
|
|
|
- name: Push image (main only)
|
|
if: github.ref == 'refs/heads/main'
|
|
run: |
|
|
set -e
|
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "${REGISTRY}" -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
|
docker push "${IMAGE}:${GITHUB_SHA}"
|
|
docker push "${IMAGE}:latest"
|
|
docker logout "${REGISTRY}"
|
|
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
needs: ci
|
|
if: github.ref == 'refs/heads/main'
|
|
steps:
|
|
- name: Trigger Rundeck deploy job
|
|
run: |
|
|
set -e
|
|
code=$(curl -fsS -o /tmp/rd.json -w '%{http_code}' -X POST \
|
|
-H "X-Rundeck-Auth-Token: ${{ secrets.RUNDECK_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
-H "Accept: application/json" \
|
|
"${{ secrets.RUNDECK_URL }}/api/40/job/${{ secrets.DEPLOY_JOB_UUID }}/run" \
|
|
--data "{\"options\":{\"image_tag\":\"${GITHUB_SHA}\"}}")
|
|
echo "Rundeck run HTTP ${code}"
|
|
python3 -c "import json;d=json.load(open('/tmp/rd.json'));print('execution id:',d.get('id'),'status:',d.get('status'),'permalink:',d.get('permalink'))"
|