-
Notifications
You must be signed in to change notification settings - Fork 283
131 lines (113 loc) · 4.6 KB
/
build-r2r-docker.yml
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Build and Publish R2R Docker Image
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to simulate (e.g., dev, dev-minor, main)'
required: false
default: 'main'
push:
branches:
- dev
- dev-minor
env:
REGISTRY_BASE: ragtoriches
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
release_version: ${{ steps.version.outputs.RELEASE_VERSION }}
registry_image: ${{ steps.version.outputs.REGISTRY_IMAGE }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch || github.ref }} # This checks out the correct branch
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install toml package
run: pip install toml
- name: Determine version and registry
id: version
run: |
VERSION=$(python -c "import toml; print(toml.load('py/pyproject.toml')['tool']['poetry']['version'])")
RELEASE_VERSION=$VERSION
# Use input branch if this is a workflow dispatch
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
BRANCH="${{ github.event.inputs.branch }}"
else
BRANCH="${{ github.ref }}"
fi
# Determine the registry based on the branch
if [ "$BRANCH" == "refs/heads/dev" ] || [ "$BRANCH" == "dev" ]; then
REGISTRY_IMAGE="${{ env.REGISTRY_BASE }}/dev"
elif [ "$BRANCH" == "refs/heads/dev-minor" ] || [ "$BRANCH" == "dev-minor" ]; then
REGISTRY_IMAGE="${{ env.REGISTRY_BASE }}/dev-minor"
else
REGISTRY_IMAGE="${{ env.REGISTRY_BASE }}/prod"
fi
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT
echo "REGISTRY_IMAGE=$REGISTRY_IMAGE" >> $GITHUB_OUTPUT
- name: Set matrix
id: set-matrix
run: |
echo "matrix={\"include\":[{\"platform\":\"amd64\",\"runner\":\"amd2\"},{\"platform\":\"arm64\",\"runner\":\"arm2\"}]}" >> $GITHUB_OUTPUT
build:
needs: prepare
strategy:
fail-fast: false
matrix: ${{fromJson(needs.prepare.outputs.matrix)}}
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.BRANCH }}
- name: Echo Commit Hash
run: |
COMMIT_HASH=$(git rev-parse HEAD)
echo "Building commit hash: $COMMIT_HASH"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker Auth
uses: docker/login-action@v3
with:
username: ${{ secrets.RAGTORICHES_DOCKER_UNAME }}
password: ${{ secrets.RAGTORICHES_DOCKER_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: ./py
file: ./py/Dockerfile
platforms: ${{ matrix.platform }}
no-cache: true
push: true
tags: |
${{ needs.prepare.outputs.REGISTRY_IMAGE }}:${{ needs.prepare.outputs.release_version }}-${{ matrix.platform }}
${{ needs.prepare.outputs.REGISTRY_IMAGE }}:latest-${{ matrix.platform }}
provenance: false
sbom: false
create-manifest:
needs: [prepare, build]
runs-on: ubuntu-latest
steps:
- name: Docker Auth
uses: docker/login-action@v3
with:
username: ${{ secrets.RAGTORICHES_DOCKER_UNAME }}
password: ${{ secrets.RAGTORICHES_DOCKER_TOKEN }}
- name: Create and push multi-arch manifest
run: |
docker buildx imagetools create -t ${{ needs.prepare.outputs.REGISTRY_IMAGE }}:${{ needs.prepare.outputs.release_version }} \
${{ needs.prepare.outputs.REGISTRY_IMAGE }}:${{ needs.prepare.outputs.release_version }}-amd64 \
${{ needs.prepare.outputs.REGISTRY_IMAGE }}:${{ needs.prepare.outputs.release_version }}-arm64
docker buildx imagetools create -t ${{ needs.prepare.outputs.REGISTRY_IMAGE }}:latest \
${{ needs.prepare.outputs.REGISTRY_IMAGE }}:${{ needs.prepare.outputs.release_version }}-amd64 \
${{ needs.prepare.outputs.REGISTRY_IMAGE }}:${{ needs.prepare.outputs.release_version }}-arm64
- name: Verify manifests
run: |
docker buildx imagetools inspect ${{ needs.prepare.outputs.REGISTRY_IMAGE }}:${{ needs.prepare.outputs.release_version }}
docker buildx imagetools inspect ${{ needs.prepare.outputs.REGISTRY_IMAGE }}:latest