Skip to content

Commit 4ee6e66

Browse files
committed
added build workflow
1 parent 7321cd7 commit 4ee6e66

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

.github/workflows/build_images.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Build Images
2+
concurrency:
3+
group: ${{ github.head_ref || github.sha }}
4+
cancel-in-progress: true
5+
6+
7+
on:
8+
push:
9+
workflow_dispatch:
10+
inputs:
11+
push_to_s3:
12+
type: boolean
13+
default: true
14+
description: "Push image to S3 bucket"
15+
test:
16+
type: boolean
17+
default: false
18+
description: "Push to prometheus-exporter-test directory"
19+
20+
jobs:
21+
build_images:
22+
strategy:
23+
matrix:
24+
arch: ["amd64", "arm64"]
25+
26+
runs-on: ${{ (matrix.arch == 'arm64') && fromJSON('["self-hosted", "ARM64"]') || fromJSON('["self-hosted", "X64"]') }}
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Set up Docker Buildx
34+
id: buildx
35+
uses: docker/setup-buildx-action@v3
36+
37+
- name: Setup AWS credentials
38+
if: ${{ inputs.push_to_s3 }}
39+
uses: aws-actions/configure-aws-credentials@v4
40+
with:
41+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
42+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
43+
aws-region: ${{ env.s3_region }}
44+
45+
- name: Extract Tag From pyproject.toml
46+
run: |
47+
tag="$(grep -Po '^version\s*=\s*"\K[0-9]+\.[0-9]+\.[0-9]+' pyproject.toml)"
48+
repo_tag="memgraph/prometheus-exporter:${tag}"
49+
echo "TAG=$tag" >> $GITHUB_ENV
50+
echo "REPO_TAG=$repo_tag" >> $GITHUB_ENV
51+
52+
- name: Set Name and Output Directory
53+
run: |
54+
name="mg-prometheus-exporter-${tag}-docker.tar.gz"
55+
echo "FILE_NAME=$name" >> $GITHUB_ENV
56+
57+
basedir="prometheus-exporter${{ inputs.test == true && '-test' || '' }}"
58+
outdir="$basedir/docker${{ (matrix.arch == 'arm64') && '-aarch64' || '' }}"
59+
echo "OUT_DIR=$outdir" >> $GITHUB_ENV
60+
61+
echo "Output: $outdir/$name"
62+
63+
- name: Build Image
64+
run: |
65+
docker build --tag "${{ env.REPO_TAG }}" --load .
66+
67+
- name: Save Image
68+
run: |
69+
mkdir -p output
70+
docker save "${{ env.REPO_TAG }}" | gzip > "output/$FILE_NAME"
71+
72+
- name: Push Image to S3
73+
if: ${{ inputs.push_to_s3 }}
74+
env:
75+
AWS_S3_BUCKET: "deps.memgraph.io"
76+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
77+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
78+
AWS_REGION: "eu-west-1"
79+
SOURCE_DIR: "output"
80+
DEST_DIR: "${{ env.OUT_DIR }}/"
81+
run: |
82+
max_attempts=3
83+
attempt_num=1
84+
until [ $attempt_num -gt $max_attempts ]
85+
do
86+
echo "Attempt $attempt_num..."
87+
# Replace the next line with your actual s3 sync command or action logic
88+
aws s3 sync $SOURCE_DIR s3://$AWS_S3_BUCKET/$DEST_DIR && break || {
89+
echo "Attempt $attempt_num failed. Retrying in 5 seconds..."
90+
sleep 5
91+
attempt_num=$((attempt_num+1))
92+
}
93+
done
94+
95+
- name: Cleanup
96+
if: always()
97+
run: |
98+
docker rmi "${{ env.REPO_TAG }}" || true

0 commit comments

Comments
 (0)