Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ name: Build simple commit

on:
push:
branches: ['*']
# the staging branch is built by staging.yml
branches-ignore: [staging]
tags-ignore: [ 'v*.*.*' ]

jobs:
Expand Down
46 changes: 35 additions & 11 deletions .github/workflows/reuse-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ name: Build

on:
workflow_call:
inputs:
ref:
description: Git ref to build (default the ref that triggered the workflow)
type: string
default: ''
tag:
description: Single image tag replacing the tags derived from the ref (e.g. staging)
type: string
default: ''
pull-requests:
description: JSON object merged into BUILD.json (baseCommit, pullRequests, excludedPullRequests of a staging build)
type: string
default: ''

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout git repository
uses: actions/checkout@v7
with:
ref: ${{ inputs.ref }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
Expand All @@ -20,9 +35,16 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# BUILD.json is added in the last layer of the Dockerfile: a build whose code is unchanged
# (a staging branch with no pull request) only rebuilds that layer
- name: Prepare BUILD.json
env:
VERSION: ${{ inputs.tag || github.ref_name }}
REPOSITORY: ${{ github.server_url }}/${{ github.repository }}
EXTRA: ${{ inputs.pull-requests || '{}' }}
run: |
echo '{"version": "${{github.ref_name}}", "repository": "${{github.server_url}}/${{github.repository}}", "commit": "${{github.sha}}", "date": "'$(date -Is)'"}' > BUILD.json
jq -n --arg version "$VERSION" --arg repository "$REPOSITORY" --arg commit "$(git rev-parse HEAD)" --arg date "$(date -Is)" --argjson extra "$EXTRA" \
'{version: $version, repository: $repository, commit: $commit, date: $date} + $extra' > BUILD.json
cat BUILD.json

- name: Prepare docker tags for main image
Expand All @@ -31,11 +53,12 @@ jobs:
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }}
type=ref,event=branch,enable=${{ inputs.tag == '' }}
type=ref,event=pr,enable=${{ inputs.tag == '' }}
type=semver,pattern={{version}},enable=${{ inputs.tag == '' }}
type=semver,pattern={{major}}.{{minor}},enable=${{ inputs.tag == '' }}
type=semver,pattern={{major}},enable=${{ inputs.tag == '' }}

- name: Build and push main image
id: docker_build_main
Expand All @@ -56,11 +79,12 @@ jobs:
with:
images: ghcr.io/${{ github.repository }}/worker
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }}
type=ref,event=branch,enable=${{ inputs.tag == '' }}
type=ref,event=pr,enable=${{ inputs.tag == '' }}
type=semver,pattern={{version}},enable=${{ inputs.tag == '' }}
type=semver,pattern={{major}}.{{minor}},enable=${{ inputs.tag == '' }}
type=semver,pattern={{major}},enable=${{ inputs.tag == '' }}

- name: Build and push worker image
id: docker_build_worker
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# the staging branch is rebuilt from scratch at every change: the default branch plus the open pull
# requests of this repository labeled "staging", then built as the image tag "staging" and deployed
# on the staging environment, which always follows that tag

name: Staging

on:
push:
branches: [master, main]
pull_request:
types: [labeled, unlabeled, synchronize, reopened, closed]
workflow_dispatch:

jobs:
# shared by the data-fair services, maintained in data-fair
rebuild:
uses: data-fair/data-fair/.github/workflows/staging-rebuild.yml@master
permissions:
contents: write
pull-requests: write

# a push made with GITHUB_TOKEN triggers no workflow: the staging branch is built and deployed here
build:
needs: rebuild
if: needs.rebuild.outputs.commit != ''
concurrency:
group: staging-build
cancel-in-progress: true
permissions:
contents: read
packages: write
uses: ./.github/workflows/reuse-build.yml
with:
# the commit of this rebuild, not the branch, which a newer rebuild may have moved already
ref: ${{ needs.rebuild.outputs.commit }}
tag: staging
pull-requests: ${{ needs.rebuild.outputs.pull-requests }}

deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Send Keel notifications to staging-koumoul.com
run: |
curl -s --fail --show-error -X POST https://keel.admin.staging-koumoul.com/v1/webhooks/native -u ${{ secrets.KEEL_STAGING_USER }}:${{ secrets.KEEL_STAGING_PASSWORD }} -d '{"name": "ghcr.io/${{ github.repository }}", "tag": "staging"}'
curl -s --fail --show-error -X POST https://keel.admin.staging-koumoul.com/v1/webhooks/native -u ${{ secrets.KEEL_STAGING_USER }}:${{ secrets.KEEL_STAGING_PASSWORD }} -d '{"name": "ghcr.io/${{ github.repository }}/worker", "tag": "staging"}'
Loading