1+ ---
2+ # Workflow do GitHub Actions para criar e publicar uma imagem Docker no Docker Hub.
3+ #
4+ # IMPORTANTE: Este workflow é chamado por outros workflows e está
5+ # centralizado aqui para facilitar a manutenção entre módulos. Por isso, certifique-se de não introduzir
6+ # mudanças que quebrem a compatibilidade ao modificar este workflow.
7+
8+ name : " modules-docker-build-push"
9+
10+ on :
11+ workflow_call :
12+ inputs :
13+ image_name :
14+ description : " Nome da imagem Docker (ex: gersonrs/minha-app)"
15+ required : true
16+ type : string
17+ context :
18+ description : " Contexto do Docker build (diretório do Dockerfile)"
19+ required : false
20+ type : string
21+ default : " ."
22+ dockerfile :
23+ description : " Caminho para o Dockerfile"
24+ required : false
25+ type : string
26+ default : " Dockerfile"
27+ platforms :
28+ description : " Plataformas para build multi-arch (ex: linux/amd64,linux/arm64)"
29+ required : false
30+ type : string
31+ default : " linux/amd64"
32+ secrets :
33+ DOCKERHUB_USERNAME :
34+ description : " Username do Docker Hub"
35+ required : true
36+ DOCKERHUB_TOKEN :
37+ description : " Token de acesso do Docker Hub"
38+ required : true
39+
40+ permissions :
41+ id-token : write
42+ packages : write
43+ contents : read
44+ attestations : write
45+
46+ env :
47+ REGISTRY : docker.io
48+
49+ jobs :
50+ docker :
51+ runs-on : ubuntu-latest
52+ # Pula o build se o PR foi criado pelo release-please
53+ if : |
54+ github.event_name != 'pull_request' ||
55+ !startsWith(github.head_ref, 'release-please--')
56+ steps :
57+ - name : Checkout
58+ uses : actions/checkout@v6
59+
60+ - name : Docker meta
61+ id : meta
62+ uses : docker/metadata-action@v5
63+ with :
64+ images : ${{ inputs.image_name }}
65+ tags : |
66+ type=ref,event=tag
67+ type=ref,event=pr
68+ type=sha,prefix=
69+
70+ - name : Set up QEMU
71+ uses : docker/setup-qemu-action@v3
72+
73+ - name : Set up Docker Buildx
74+ uses : docker/setup-buildx-action@v3
75+
76+ - name : Login to DockerHub
77+ if : github.event_name != 'pull_request'
78+ uses : docker/login-action@v3
79+ with :
80+ username : ${{ secrets.DOCKERHUB_USERNAME }}
81+ password : ${{ secrets.DOCKERHUB_TOKEN }}
82+
83+ - name : Build and push
84+ id : push
85+ uses : docker/build-push-action@v6
86+ with :
87+ context : ${{ inputs.context }}
88+ file : ${{ inputs.context }}/${{ inputs.dockerfile }}
89+ platforms : ${{ inputs.platforms }}
90+ push : ${{ github.event_name != 'pull_request' }}
91+ tags : ${{ steps.meta.outputs.tags }}
92+ labels : ${{ steps.meta.outputs.labels }}
93+ annotations : ${{ steps.meta.outputs.annotations }}
94+ cache-from : type=gha
95+ cache-to : type=gha,mode=max
0 commit comments