Add prefetch #98
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: docker | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
tags: | |
- "*" | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
outputs: | |
branch_name: ${{steps.metadata.outputs.branch_name}} | |
image_branch_name: ${{steps.metadata.outputs.image_branch_name}} | |
strategy: | |
fail-fast: false | |
matrix: | |
cloud_image_tag_prefix: | |
- pg16 | |
pgversion: | |
- 16 | |
tsversion: | |
- 2.13 | |
steps: | |
- name: Checkout Timescale Vector | |
uses: actions/checkout@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1-node16 | |
with: | |
aws-access-key-id: ${{ secrets.ORG_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.ORG_AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
- name: Login to Amazon ECR | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Gather metadata | |
id: metadata | |
run: | | |
tsmajor=$(echo ${{ matrix.tsversion }} | cut -d. -f1) | |
tsmajmin=$(echo ${{ matrix.tsversion }} | cut -d. -f1,2) | |
commit_sha=$(git rev-parse --short "${{ github.event.pull_request.head.sha || github.sha }}") | |
branch_name=$(echo ${{github.head_ref || github.ref_name}}) | |
image_branch_name=$(echo ${branch_name} | sed 's#/#-#') | |
base_cloud_image_tag=$(aws ecr describe-images --repository-name 'timescaledb-cloud' --region us-east-1 --query 'imageDetails[?imageTags[?starts_with(@,`${{ matrix.cloud_image_tag_prefix }}`) && contains(@, `ts${{ matrix.tsversion }}`) && contains(@, `amd64`)]].imageTags' --output text | sort -V | tail -n1) | |
echo "tsmajor=${tsmajor}" >> ${GITHUB_OUTPUT} | |
echo "tsmajmin=${tsmajmin}" >> ${GITHUB_OUTPUT} | |
echo "branch_name=${branch_name}" >> ${GITHUB_OUTPUT} | |
echo "image_branch_name=${image_branch_name}" >> ${GITHUB_OUTPUT} | |
echo "commit_sha=${commit_sha}" >> ${GITHUB_OUTPUT} | |
echo "base_cloud_image_tag=${base_cloud_image_tag}" >> ${GITHUB_OUTPUT} | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
env: | |
DOCKER_PUSH_REQUIRED: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login == 'timescale' }} # Don't run docker push when this is a PR from a fork | |
with: | |
build-args: | | |
PG_VERSION=${{ matrix.pgversion }} | |
TIMESCALEDB_VERSION_MAJMIN=${{ steps.metadata.outputs.tsmajmin }} | |
BASE_IMAGE=142548018081.dkr.ecr.us-east-1.amazonaws.com/timescaledb-cloud:${{ steps.metadata.outputs.base_cloud_image_tag }} | |
secrets: | | |
"GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" | |
context: . | |
push: ${{ env.DOCKER_PUSH_REQUIRED == 'true' }} | |
load: ${{ env.DOCKER_PUSH_REQUIRED != 'true' }} | |
tags: | | |
ghcr.io/timescale/dev_timescale_vector:${{steps.metadata.outputs.image_branch_name}}-ts${{matrix.tsversion}}-pg${{matrix.pgversion}} | |
labels: | | |
org.opencontainers.image.source= | |
org.opencontainers.image.revision= | |
org.opencontainers.image.created= | |
cache-from: type=gha,scope=${{matrix.pgversion}}-${{matrix.tsversion}} | |
cache-to: type=gha,mode=max,scope=${{matrix.pgversion}}-${{matrix.tsversion}} | |
- name: Publish images to ECR | |
uses: akhilerm/tag-push-action@v2.0.0 | |
with: | |
src: ghcr.io/timescale/dev_timescale_vector:${{steps.metadata.outputs.image_branch_name}}-ts${{matrix.tsversion}}-pg${{matrix.pgversion}} | |
dst: 142548018081.dkr.ecr.us-east-1.amazonaws.com/timescale-vector:${{steps.metadata.outputs.image_branch_name}}-${{steps.metadata.outputs.commit_sha}}-ts${{matrix.tsversion}}-pg${{matrix.pgversion}} | |
# This allows us to set a single job which must pass in GitHub's branch protection rules, | |
# otherwise we have to keep updating them as we add or remove postgres versions etc. | |
docker-result: | |
name: docker result | |
if: always() | |
needs: | |
- docker | |
runs-on: ubuntu-latest | |
steps: | |
- name: Mark the job as a success | |
if: needs.docker.result == 'success' | |
run: exit 0 | |
- name: Mark the job as a failure | |
if: needs.docker.result != 'success' | |
run: exit 1 |