2020-11-05 14:35:31 +00:00
|
|
|
name: Docker
|
2020-11-05 14:31:58 +00:00
|
|
|
|
|
|
|
on:
|
2022-04-14 14:08:39 +00:00
|
|
|
# push:
|
|
|
|
# branches:
|
|
|
|
# - master
|
|
|
|
# tags:
|
|
|
|
# - v[0-9]+.[0-9]+.[0-9]+
|
2020-11-05 14:31:58 +00:00
|
|
|
pull_request:
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
docker:
|
|
|
|
name: Docker
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2022-03-02 04:08:38 +00:00
|
|
|
uses: actions/checkout@v3
|
2020-11-05 14:31:58 +00:00
|
|
|
|
|
|
|
- name: Calculate Docker image tags
|
|
|
|
id: tags
|
|
|
|
env:
|
|
|
|
DOCKER_IMAGES: "ghcr.io/dexidp/dex dexidp/dex"
|
|
|
|
run: |
|
|
|
|
case $GITHUB_REF in
|
|
|
|
refs/tags/*) VERSION=${GITHUB_REF#refs/tags/};;
|
|
|
|
refs/heads/*) VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g');;
|
|
|
|
refs/pull/*) VERSION=pr-${{ github.event.number }};;
|
|
|
|
*) VERSION=sha-${GITHUB_SHA::8};;
|
|
|
|
esac
|
|
|
|
|
|
|
|
TAGS=()
|
|
|
|
for image in $DOCKER_IMAGES; do
|
|
|
|
TAGS+=("${image}:${VERSION}")
|
|
|
|
|
|
|
|
if [[ "${{ github.event.repository.default_branch }}" == "$VERSION" ]]; then
|
|
|
|
TAGS+=("${image}:latest")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo ::set-output name=version::${VERSION}
|
|
|
|
echo ::set-output name=tags::$(IFS=,; echo "${TAGS[*]}")
|
|
|
|
echo ::set-output name=commit_hash::${GITHUB_SHA::8}
|
|
|
|
echo ::set-output name=build_date::$(git show -s --format=%cI)
|
|
|
|
|
|
|
|
- name: Set up QEMU
|
2022-05-20 13:15:37 +00:00
|
|
|
uses: docker/setup-qemu-action@v2
|
2020-11-05 14:31:58 +00:00
|
|
|
with:
|
|
|
|
platforms: all
|
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
2022-05-20 13:52:12 +00:00
|
|
|
uses: docker/setup-buildx-action@v2
|
2020-11-05 14:31:58 +00:00
|
|
|
with:
|
|
|
|
install: true
|
|
|
|
version: latest
|
|
|
|
# TODO: Remove driver-opts once fix is released docker/buildx#386
|
|
|
|
driver-opts: image=moby/buildkit:master
|
|
|
|
|
|
|
|
- name: Login to GitHub Container Registry
|
2022-05-20 13:15:47 +00:00
|
|
|
uses: docker/login-action@v2
|
2020-11-05 14:31:58 +00:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.repository_owner }}
|
2021-06-28 20:07:14 +00:00
|
|
|
password: ${{ github.token }}
|
2020-11-05 14:31:58 +00:00
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
|
|
|
- name: Login to Docker Hub
|
2022-05-20 13:15:47 +00:00
|
|
|
uses: docker/login-action@v2
|
2020-11-05 14:31:58 +00:00
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
|
|
|
- name: Build and push
|
2022-05-20 12:58:44 +00:00
|
|
|
uses: docker/build-push-action@v3
|
2020-11-05 14:31:58 +00:00
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
platforms: linux/amd64,linux/arm/v7,linux/arm64
|
2022-05-14 13:50:29 +00:00
|
|
|
# cache-from: type=gha
|
|
|
|
# cache-to: type=gha,mode=max
|
2020-11-05 14:31:58 +00:00
|
|
|
push: ${{ github.event_name == 'push' }}
|
|
|
|
tags: ${{ steps.tags.outputs.tags }}
|
|
|
|
build-args: |
|
|
|
|
VERSION=${{ steps.tags.outputs.version }}
|
|
|
|
COMMIT_HASH=${{ steps.tags.outputs.commit_hash }}
|
|
|
|
BUILD_DATE=${{ steps.tags.outputs.build_date }}
|
|
|
|
labels: |
|
|
|
|
org.opencontainers.image.title=${{ github.event.repository.name }}
|
|
|
|
org.opencontainers.image.description=${{ github.event.repository.description }}
|
|
|
|
org.opencontainers.image.url=${{ github.event.repository.html_url }}
|
|
|
|
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
|
|
|
|
org.opencontainers.image.version=${{ steps.tags.outputs.version }}
|
|
|
|
org.opencontainers.image.created=${{ steps.tags.outputs.build_date }}
|
|
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
|
|
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
|
|
|
|
org.opencontainers.image.documentation=https://dexidp.io/docs/
|
2022-01-26 14:38:31 +00:00
|
|
|
|
|
|
|
- name: Run Trivy vulnerability scanner
|
2022-04-19 04:08:41 +00:00
|
|
|
uses: aquasecurity/trivy-action@0.2.5
|
2022-01-26 14:38:31 +00:00
|
|
|
with:
|
|
|
|
image-ref: "ghcr.io/dexidp/dex:${{ steps.tags.outputs.version }}"
|
|
|
|
format: "template"
|
|
|
|
template: "@/contrib/sarif.tpl"
|
|
|
|
output: "trivy-results.sarif"
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
|
|
|
- name: Upload Trivy scan results to GitHub Security tab
|
2022-04-26 04:09:06 +00:00
|
|
|
uses: github/codeql-action/upload-sarif@v2
|
2022-01-26 14:38:31 +00:00
|
|
|
with:
|
|
|
|
sarif_file: "trivy-results.sarif"
|
|
|
|
if: github.event_name == 'push'
|