diff --git a/.github/workflows/docker_image_ci.yml b/.github/workflows/docker_image_ci.yml index 543cb7c..439c217 100644 --- a/.github/workflows/docker_image_ci.yml +++ b/.github/workflows/docker_image_ci.yml @@ -1,74 +1,38 @@ -name: Docker Image CI +name: Publish Docker image on: - pull_request: - push: - workflow_dispatch: # manual trigger + release: + types: [published] jobs: - docker: + push_to_registries: + name: Push Docker image to multiple registries runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - component: scms - version: ${GITHUB_REF##*/} - context: version3 - title: SCMS - description: "Service Chain Management System" - url: https://github.com/s2n-cnit/scms - + permissions: + packages: write + contents: read steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Check out the repo + uses: actions/checkout@v3 - - name: Repo metadata - id: repo - uses: actions/github-script@v3 + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 with: - script: | - const repo = await github.repos.get(context.repo) - return repo.data - - - name: Prepare - id: prep - run: | - echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') - echo ::set-output name=branch::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g') - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + images: | + ghcr.io/${{ github.repository }} - - name: Build and push - id: docker_build - uses: docker/build-push-action@v2 + - name: Build and push Docker images + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: - context: ${{ matrix.context }} - file: ${{ matrix.context }}/Dockerfile - build-args: | - VERSION=${{ matrix.version }} - no-cache: true + context: . push: true - tags: guardproject/${{ matrix.component }}:${{ matrix.version }} - labels: | - org.opencontainers.image.title=${{ matrix.title }} - org.opencontainers.image.description=${{ matrix.description }} - org.opencontainers.image.url=${{ matrix.url }} - org.opencontainers.image.source=${{ fromJson(steps.repo.outputs.result).html_url }}/tree/${{ steps.prep.outputs.branch }}/${{ matrix.context }} - org.opencontainers.image.version=${{ matrix.version }} - org.opencontainers.image.created=${{ steps.prep.outputs.created }} - org.opencontainers.image.revision=${{ github.sha }} - org.opencontainers.image.licenses=${{ fromJson(steps.repo.outputs.result).license.spdx_id }} - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}