build container #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build container | |
on: | |
# triggered by user action only | |
workflow_dispatch: | |
inputs: | |
PG_VERSION: | |
description: 'Postgres version' | |
required: true | |
default: '15.3' | |
EXTENSIONS: | |
description: 'Postgres extensions to install' | |
required: true | |
default: 'cron timescaledb' | |
TIMESCALEDB_VERSION: | |
description: 'TimescaleDB version' | |
required: true | |
default: '2.11.0' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: docker/setup-buildx-action@v2 | |
- uses: docker/login-action@v2 | |
# authenticate ghcr.io | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: calculate image tag | |
id: vars | |
run: | | |
# step 1: order extensions alphabetically | |
export EXTENSIONS=$(echo "${{ github.event.inputs.EXTENSIONS }}" | tr ' ' '\n' | sort | tr '\n' ' ') | |
# this is good but it leaves a trailing space. Fix it: | |
export EXTENSIONS=$(echo "${EXTENSIONS}" | sed 's/ $//g') | |
# step 2: if exists, replace extension timescaledb with its versioned equivalent; replace spaces with dashes | |
export EXTENSIONS=$(echo "${{ github.event.inputs.EXTENSIONS }}" | sed 's/timescaledb/timescaledb-${{ github.event.inputs.TIMESCALEDB_VERSION }}/g;s/ /-/g') | |
# step 3: output variable to github action | |
echo "IMAGE_TAG=${{ github.event.inputs.PG_VERSION }}-${EXTENSIONS}" >> $GITHUB_OUTPUT | |
- uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ghcr.io/${{ github.repository_owner }}/postgresql:${{ steps.vars.outputs.IMAGE_TAG }} | |
build-args: | | |
POSTGRESQL_VERSION=${{ github.event.inputs.PG_VERSION }} | |
EXTENSIONS=${{ github.event.inputs.EXTENSIONS }} | |
TIMESCALEDB_VERSION=${{ github.event.inputs.TIMESCALEDB_VERSION }} |