refactor: migrar GitLab → Gitea (aulas 10, 11, 13)
- Aula 10: Gitea + Registry + Actions + Runner (substituiu GitLab) - gitea-values.yaml: PostgreSQL standalone, Valkey standalone, ~800Mi RAM - setup.sh/cleanup.sh: namespace gitea, Helm gitea-charts/gitea + actions - README.md: documentação completa com de→para (GitLab/Harbor/Tekton vs Gitea) - Aula 11: ArgoCD (GitOps) — removido GitLab Runner (runner vive na aula-10) - setup.sh: só ArgoCD, integração SSH com Gitea - node-bugado/.gitea/workflows/ci.yml: pipeline convertida - Aula 13: Container Factory — atualizado para Gitea - setup.sh/cleanup.sh: referências GitLab → Gitea - pipelines/postgresql/ci.yml: Gitea Actions workflow - README.md: conexão com act_runner explicada - CLAUDE.md: tabela de aulas atualizada
This commit is contained in:
157
aula-13/pipelines/postgresql/ci.yml
Normal file
157
aula-13/pipelines/postgresql/ci.yml
Normal file
@@ -0,0 +1,157 @@
|
||||
# =============================================================================
|
||||
# Gitea Actions Workflow - PostgreSQL Container Factory
|
||||
# =============================================================================
|
||||
#
|
||||
# Build de imagem PostgreSQL customizada em formato eStargz.
|
||||
# Push para Gitea Container Registry com lazy pulling habilitado.
|
||||
#
|
||||
# Requisitos:
|
||||
# - Gitea Actions Runner com Docker (aula-10)
|
||||
# - Secret REGISTRY_TOKEN configurado no repo
|
||||
#
|
||||
# Uso:
|
||||
# 1. Criar org 'factory' no Gitea
|
||||
# 2. Criar repositório 'postgresql' na org
|
||||
# 3. Copiar Dockerfile, postgresql.conf e este ci.yml para .gitea/workflows/
|
||||
# 4. Push para main - pipeline roda automaticamente
|
||||
#
|
||||
# =============================================================================
|
||||
|
||||
name: Build PostgreSQL
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ['*']
|
||||
|
||||
env:
|
||||
REGISTRY: gitea.kube.quest
|
||||
IMAGE_NAME: factory/postgresql
|
||||
POSTGRES_VERSION: "17"
|
||||
|
||||
jobs:
|
||||
# ===========================================================================
|
||||
# BUILD - Construir imagem em formato eStargz
|
||||
# ===========================================================================
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Gitea Registry
|
||||
run: |
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ env.REGISTRY }} \
|
||||
-u ${{ gitea.actor }} --password-stdin
|
||||
|
||||
- name: Build eStargz image
|
||||
run: |
|
||||
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-8)
|
||||
echo "Building ${{ env.IMAGE_NAME }}:${{ env.POSTGRES_VERSION }}-${SHORT_SHA} with eStargz compression"
|
||||
docker buildx build \
|
||||
--output type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.POSTGRES_VERSION }}-${SHORT_SHA},push=true,compression=estargz,force-compression=true,oci-mediatypes=true \
|
||||
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
||||
--label "org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
||||
--build-arg POSTGRES_VERSION=${{ env.POSTGRES_VERSION }} \
|
||||
.
|
||||
|
||||
# ===========================================================================
|
||||
# TEST - Testar imagem construída
|
||||
# ===========================================================================
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- name: Login to Gitea Registry
|
||||
run: |
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ env.REGISTRY }} \
|
||||
-u ${{ gitea.actor }} --password-stdin
|
||||
|
||||
- name: Test PostgreSQL image
|
||||
run: |
|
||||
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-8)
|
||||
echo "Testing PostgreSQL image..."
|
||||
|
||||
docker run -d --name pg-test \
|
||||
-e POSTGRES_PASSWORD=testpassword \
|
||||
-e POSTGRES_DB=testdb \
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.POSTGRES_VERSION }}-${SHORT_SHA}
|
||||
|
||||
# Aguardar inicialização (30s max)
|
||||
for i in $(seq 1 30); do
|
||||
if docker exec pg-test pg_isready -U postgres -d testdb 2>/dev/null; then
|
||||
echo "PostgreSQL ready!"
|
||||
break
|
||||
fi
|
||||
echo "Waiting for PostgreSQL... ($i/30)"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# Verificar healthcheck
|
||||
docker exec pg-test pg_isready -U postgres -d testdb
|
||||
|
||||
# Testar conexão e queries básicas
|
||||
docker exec pg-test psql -U postgres -d testdb -c "SELECT version();"
|
||||
docker exec pg-test psql -U postgres -d testdb -c "SHOW shared_buffers;"
|
||||
docker exec pg-test psql -U postgres -d testdb -c "SHOW max_connections;"
|
||||
|
||||
# Testar criação de tabela
|
||||
docker exec pg-test psql -U postgres -d testdb -c "CREATE TABLE test (id serial PRIMARY KEY, name text);"
|
||||
docker exec pg-test psql -U postgres -d testdb -c "INSERT INTO test (name) VALUES ('test');"
|
||||
docker exec pg-test psql -U postgres -d testdb -c "SELECT * FROM test;"
|
||||
docker exec pg-test psql -U postgres -d testdb -c "DROP TABLE test;"
|
||||
|
||||
# Cleanup
|
||||
docker stop pg-test && docker rm pg-test
|
||||
echo "All tests passed!"
|
||||
|
||||
# ===========================================================================
|
||||
# PUSH - Tag como versão e latest
|
||||
# ===========================================================================
|
||||
push:
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
if: github.ref == 'refs/heads/main'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Gitea Registry
|
||||
run: |
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ env.REGISTRY }} \
|
||||
-u ${{ gitea.actor }} --password-stdin
|
||||
|
||||
- name: Push version and latest tags (eStargz)
|
||||
run: |
|
||||
echo "Tagging and pushing final images..."
|
||||
|
||||
# Tag como versão (17)
|
||||
docker buildx build \
|
||||
--output type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.POSTGRES_VERSION }},push=true,compression=estargz,force-compression=true,oci-mediatypes=true \
|
||||
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
||||
--label "org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
||||
.
|
||||
|
||||
# Tag como latest
|
||||
docker buildx build \
|
||||
--output type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,push=true,compression=estargz,force-compression=true,oci-mediatypes=true \
|
||||
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
||||
--label "org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
||||
.
|
||||
|
||||
- name: Push GZIP version (for benchmark)
|
||||
run: |
|
||||
docker buildx build \
|
||||
--output type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.POSTGRES_VERSION }}-gzip,push=true,compression=gzip,oci-mediatypes=true \
|
||||
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
||||
--label "org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
||||
.
|
||||
|
||||
echo "Images pushed:"
|
||||
echo " - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.POSTGRES_VERSION }} (eStargz)"
|
||||
echo " - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.POSTGRES_VERSION }}-gzip (GZIP)"
|
||||
echo " - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest (eStargz)"
|
||||
Reference in New Issue
Block a user