diff --git a/.dockerignore b/.dockerignore index ba077a4031..56588ee497 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,3 @@ -bin +.github/ +bin/ +tmp/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15e5d5e0b0..f98bc4a0be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: jobs: build: name: Build - runs-on: ubuntu-16.04 + runs-on: ubuntu-latest env: GOFLAGS: -mod=readonly @@ -81,63 +81,3 @@ jobs: # Ensure proto generation doesn't depend on external packages. - name: Verify proto run: make verify-proto - - docker: - name: Docker - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Get Version - id: info - run: | - echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') - - - name: Determine Docker Tag - uses: haya14busa/action-cond@v1 - id: imagetag - with: - cond: ${{ github.event_name == 'pull_request' }} - if_true: ${{ github.sha }} - if_false: 'master' - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - with: - platforms: all - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - 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 DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - if: github.event_name == 'push' - - - name: Build and Push - uses: docker/build-push-action@v2 - with: - context: . - file: Dockerfile - platforms: linux/amd64,linux/arm/v7,linux/arm64 - push: ${{ github.event_name == 'push' }} - tags: dexidp/dex:${{ steps.imagetag.outputs.value }} - 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.imagetag.outputs.value }} - org.opencontainers.image.created=${{ steps.info.outputs.created }} - org.opencontainers.image.revision=${{ github.sha }} - org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000000..5fd46ebcc4 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,94 @@ +name: Docker + +on: + push: + branches: + - master + tags: + - v[0-9]+.[0-9]+.[0-9]+ + pull_request: + +jobs: + docker: + name: Docker + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - 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 + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + 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 + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CR_PAT }} + if: github.event_name == 'push' + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + if: github.event_name == 'push' + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/arm/v7,linux/arm64 + 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/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 9a655935fb..0000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Release - -on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' - -jobs: - docker: - name: Docker - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Get Version - id: info - run: | - VERSION=$(shell ./scripts/git-version) - echo ::set-output name=version::${VERSION} - echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - with: - platforms: all - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - 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 DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and Push - uses: docker/build-push-action@v2 - with: - context: . - file: Dockerfile - platforms: linux/amd64,linux/arm/v7,linux/arm64 - push: true - tags: | - dexidp/dex:latest - dexidp/dex:${{ steps.info.outputs.version }} - 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.info.outputs.version }} - org.opencontainers.image.created=${{ steps.info.outputs.created }} - org.opencontainers.image.revision=${{ github.sha }} - org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} diff --git a/Dockerfile b/Dockerfile index d9d050d085..bf50d51e91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,12 @@ ENV GOOS=${TARGETOS} \ RUN apk add --no-cache --update alpine-sdk +ARG GOPROXY + +COPY go.mod go.sum ./ +COPY api/v2/go.mod api/v2/go.sum ./api/v2/ +RUN go mod download + COPY . . RUN make release-binary