1+ name : Docker
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ target_platforms :
7+ description : " Target platforms for buildx (e.g., linux/amd64,linux/arm64)"
8+ required : false
9+ default : " linux/amd64"
10+ skip_unit_tests :
11+ description : " Skip unit tests when building this image"
12+ type : boolean
13+ default : true
14+ schedule :
15+ - cron : " 38 3 * * *"
16+ push :
17+ branches :
18+ - master
19+ paths-ignore :
20+ - " README.md"
21+
22+ env :
23+ DESTINATION_REGISTRY : ghcr.io
24+ DESTINATION_IMAGE_NAME : ${{ github.repository }}
25+ DESTINATION_REGISTRY_USERNAME : ${{ secrets.DESTINATION_REGISTRY_USERNAME || github.actor }}
26+ DESTINATION_REGISTRY_PASSWORD : ${{ secrets.DESTINATION_REGISTRY_PASSWORD || secrets.GITHUB_TOKEN }}
27+
28+ ODOO_BASE_IMAGE : ghcr.io/adomi-io/odoo:19.0
29+
30+ jobs :
31+ build-and-push :
32+ runs-on : ubuntu-latest
33+
34+ concurrency :
35+ group : docker-${{ github.workflow }}-${{ github.ref }}
36+ cancel-in-progress : true
37+
38+ permissions :
39+ contents : read
40+ packages : write
41+
42+ env :
43+ TARGET_PLATFORMS : ${{ github.event_name == 'workflow_dispatch' && inputs.target_platforms || 'linux/amd64' }}
44+ SKIP_UNIT_TESTS : ${{ github.event_name == 'workflow_dispatch' && inputs.skip_unit_tests || false }}
45+ IS_MASTER : ${{ github.ref_name == 'master' }}
46+ IMAGE_TAG : ${{ github.ref_name }}
47+
48+ steps :
49+ - name : Checkout repository
50+ uses : actions/checkout@v4
51+
52+ - name : Set up QEMU
53+ uses : docker/setup-qemu-action@v3
54+
55+ - name : Set up Docker Buildx
56+ uses : docker/setup-buildx-action@v3
57+
58+ - name : Build Docker image for testing
59+ if : ${{ !env.SKIP_UNIT_TESTS }}
60+ uses : docker/build-push-action@v5
61+ with :
62+ build-args : |
63+ ODOO_BASE_IMAGE=${{ env.ODOO_BASE_IMAGE }}
64+ tags : ${{ env.DESTINATION_REGISTRY }}/${{ env.DESTINATION_IMAGE_NAME }}:${{ env.IMAGE_TAG }}-test
65+ push : false
66+ load : true
67+
68+ - name : Run unit tests
69+ if : ${{ !env.SKIP_UNIT_TESTS }}
70+ working-directory : tests
71+ run : ./unit-tests.sh
72+ env :
73+ TESTS_IMAGE_TAG : ${{ env.DESTINATION_REGISTRY }}/${{ env.DESTINATION_IMAGE_NAME }}:${{ env.IMAGE_TAG }}-test
74+ SKIP_BUILD : true
75+
76+ - name : Log into destination registry
77+ if : github.event_name != 'pull_request'
78+ uses : docker/login-action@v3
79+ with :
80+ registry : ${{ env.DESTINATION_REGISTRY }}
81+ username : ${{ env.DESTINATION_REGISTRY_USERNAME }}
82+ password : ${{ env.DESTINATION_REGISTRY_PASSWORD }}
83+
84+ - name : Extract Docker metadata
85+ if : github.event_name != 'pull_request'
86+ id : meta
87+ uses : docker/metadata-action@v5
88+ with :
89+ images : ${{ env.DESTINATION_REGISTRY }}/${{ env.DESTINATION_IMAGE_NAME }}
90+ tags : |
91+ # Tag by ref (master) or explicit override from workflow_dispatch
92+ type=raw,value=${{ env.IMAGE_TAG }}
93+ # Add short sha tag for traceability
94+ type=sha,format=short
95+ # Add latest only on master
96+ type=raw,value=latest,enable=${{ env.IS_MASTER == 'true' }}
97+
98+ - name : Build and push multi-arch Docker image
99+ if : github.event_name != 'pull_request'
100+ uses : docker/build-push-action@v5
101+ with :
102+ platforms : ${{ env.TARGET_PLATFORMS }}
103+ build-args : |
104+ ODOO_BASE_IMAGE=${{ env.ODOO_BASE_IMAGE }}
105+ tags : ${{ steps.meta.outputs.tags }}
106+ labels : ${{ steps.meta.outputs.labels }}
107+ push : true
0 commit comments