This repository has been archived by the owner on Feb 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (74 loc) · 3.23 KB
/
build.yaml
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
name: Build & Push OCI Image to OCI Image Registry
on:
workflow_call:
inputs:
dockerfile:
required: true
type: string
images:
required: true
type: string
secrets:
ghcr-username:
required: true
ghcr-access-token:
required: true
permissions:
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check Out Repository
uses: actions/checkout@v4.2.2
- name: Set up QEMU for Docker Buildx
uses: docker/setup-qemu-action@v3.2.0
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3.8.0
- name: Get Postgres version in Dockerfile
id: postgres
run: |
export VERSION=$(cat ${{ inputs.dockerfile }} | sed -n 's/.*postgresql:\([0-9.]*\).*/\1/p')
echo "MAJOR=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_OUTPUT
echo "MINOR=$(echo $VERSION | cut -d. -f2)" >> $GITHUB_OUTPUT
echo "PATCH=$(echo $VERSION | cut -d. -f3)" >> $GITHUB_OUTPUT
- name: Get TimescaleDB version in Dockerfile
id: timescaledb
run: |
export VERSION=$(cat ${{ inputs.dockerfile }} | sed -n 's/.*timescale\/timescaledb:\([0-9.]*\).*/\1/p')
echo "MAJOR=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_OUTPUT
echo "MINOR=$(echo $VERSION | cut -d. -f2)" >> $GITHUB_OUTPUT
echo "PATCH=$(echo $VERSION | cut -d. -f3)" >> $GITHUB_OUTPUT
- name: Generate Docker image metadata
uses: docker/metadata-action@v5.6.1
id: meta
with:
images: ${{ inputs.images }}
tags: |
${{ steps.postgres.outputs.MAJOR }}
${{ steps.postgres.outputs.MAJOR }}.${{ steps.postgres.outputs.MINOR }}
${{ steps.postgres.outputs.MAJOR }}.${{ steps.postgres.outputs.MINOR }}.${{ steps.postgres.outputs.PATCH }}
${{ steps.postgres.outputs.MAJOR }}-${{ steps.timescaledb.outputs.MAJOR }}
${{ steps.postgres.outputs.MAJOR }}.${{ steps.postgres.outputs.MINOR }}-${{ steps.timescaledb.outputs.MAJOR }}.${{ steps.timescaledb.outputs.MINOR }}
${{ steps.postgres.outputs.MAJOR }}.${{ steps.postgres.outputs.MINOR }}.${{ steps.postgres.outputs.PATCH }}-${{ steps.timescaledb.outputs.MAJOR }}.${{ steps.timescaledb.outputs.MINOR }}.${{ steps.timescaledb.outputs.PATCH }}
type=sha,prefix=${{ steps.postgres.outputs.MAJOR }}-,suffix=,format=short
type=sha,prefix=${{ steps.postgres.outputs.MAJOR }}-,suffix=,format=long
- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ secrets.ghcr-username }}
password: ${{ secrets.ghcr-access-token }}
- name: Build and push the Docker image from the specified Dockerfile
id: docker_build
uses: docker/build-push-action@v6.10.0
with:
context: .
file: ./${{ inputs.dockerfile }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}