Skip to content

Docker

Docker #236

Workflow file for this run

name: Docker
on:
pull_request:
workflow_run:
workflows: [ "Build and Test" ]
branches: [ master ]
types: [ completed ]
jobs:
setup:
runs-on: ubuntu-latest
environment: docker
outputs:
ARTIFACT_NAME: ${{ steps.setter.outputs.ARTIFACT_NAME }}
IMAGE_TAG: ${{ steps.setter.outputs.IMAGE_TAG }}
steps:
- id: setter
run: |
BRANCH_NAME=${GITHUB_HEAD_REF-}
if [ "$BRANCH_NAME" == "" ]; then
BRANCH_NAME=${{ github.event.workflow_run.head_branch }}
fi
TAG="$BRANCH_NAME-${{ github.sha }}-$(date +%s)"
echo "::set-output name=IMAGE_TAG::$TAG"
echo "::set-output name=ARTIFACT_NAME::ippsample-$TAG"
build:
runs-on: ubuntu-latest
environment: docker
needs: setup
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build and export
uses: docker/build-push-action@v2
with:
context: .
tags: ippsample:${{ needs.setup.outputs.IMAGE_TAG }}
outputs: type=docker,dest=/tmp/ippsample.tar
-
name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ needs.setup.outputs.ARTIFACT_NAME }}
path: /tmp/ippsample.tar
retention-days: 1
test:
runs-on: ubuntu-latest
environment: docker
needs: [ build, setup ]
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ needs.setup.outputs.ARTIFACT_NAME }}
path: /tmp
-
name: Load image
run: |
docker load --input /tmp/ippsample.tar
-
name: Detail image
run: |
docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}\t{{.CreatedSince}}"
-
name: Call commands
run: |
docker run ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ippserver --version
docker run ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ippeveprinter --version
docker run ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ippfind --version
docker run ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ipptool --version
secrets:
runs-on: ubuntu-latest
environment: docker
needs: test
if: github.event.workflow_run.conclusion == 'success'
outputs:
PUSH_TO_HUB: ${{ steps.setter.outputs.PUSH_TO_HUB }}
PUSH_TO_GHCR: ${{ steps.setter.outputs.PUSH_TO_GHCR }}
steps:
- id: setter
run: >
echo "::set-output name=PUSH_TO_HUB::${{ secrets.DOCKERHUB_IMAGE != '' }}";
echo "::set-output name=PUSH_TO_GHCR::${{ secrets.GHCR_IMAGE != '' }}";
hub:
runs-on: ubuntu-latest
environment: docker
needs: [ secrets, setup ]
if: needs.secrets.outputs.PUSH_TO_HUB == 'true'
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ needs.setup.outputs.ARTIFACT_NAME }}
path: /tmp
-
name: Load image
run: |
docker load --input /tmp/ippsample.tar
-
name: Tag image
run: |
docker tag ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ${{ secrets.DOCKERHUB_IMAGE }}:${{ needs.setup.outputs.IMAGE_TAG }}
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Push image
run: |
docker push ${{ secrets.DOCKERHUB_IMAGE }}:${{ needs.setup.outputs.IMAGE_TAG }}
ghcr:
runs-on: ubuntu-latest
environment: docker
needs: [ secrets, setup ]
if: needs.secrets.outputs.PUSH_TO_GHCR == 'true'
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ needs.setup.outputs.ARTIFACT_NAME }}
path: /tmp
-
name: Load image
run: |
docker load --input /tmp/ippsample.tar
-
name: Tag image
run: |
docker tag ippsample:${{ needs.setup.outputs.IMAGE_TAG }} ghcr.io/${{ secrets.GHCR_IMAGE }}:${{ needs.setup.outputs.IMAGE_TAG }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Push image
run: |
docker push ghcr.io/${{ secrets.GHCR_IMAGE }}:${{ needs.setup.outputs.IMAGE_TAG }}