Repository navigation
77 lines (67 loc) · 2.29 KB
/
Copy pathpackaging.yml
File metadata and controls
77 lines (67 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Publish Docker Images
on:
push:
branches: [ "main" ]
tags: [ "v*.*.*" ]
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
build-and-publish:
name: Build and Push Docker Image
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Resolve registries
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_APP_NAME: ${{ secrets.DOCKER_APP_NAME }}
run: |
images="ghcr.io/${GITHUB_REPOSITORY,,}"
if [ -n "$DOCKER_USERNAME" ] && [ -n "$DOCKER_PASSWORD" ]; then
images="$images"$'\n'"docker.io/$DOCKER_USERNAME/${DOCKER_APP_NAME:-api-smartpot}"
echo "DOCKERHUB=true" >> "$GITHUB_ENV"
else
echo "::notice::Sin DOCKER_USERNAME y DOCKER_PASSWORD la imagen solo se publica en GHCR."
fi
{ echo "IMAGES<<EOF"; echo "$images"; echo "EOF"; } >> "$GITHUB_ENV"
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGES }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=short
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
if: env.DOCKERHUB == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: mode=max
sbom: true