Add complete workflow example

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-08-18 22:54:44 +02:00
parent 38c1f188ca
commit 25fd13d2a5
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
2 changed files with 90 additions and 20 deletions

105
README.md
View File

@ -6,7 +6,9 @@ ___
* [Usage](#usage) * [Usage](#usage)
* [Quick start](#quick-start) * [Quick start](#quick-start)
* [Multi-platform image](#multi-platform-image)
* [Git context](#git-context) * [Git context](#git-context)
* [Complete workflow](#complete-workflow)
* [Customizing](#customizing) * [Customizing](#customizing)
* [inputs](#inputs) * [inputs](#inputs)
* [outputs](#outputs) * [outputs](#outputs)
@ -25,11 +27,8 @@ build-secrets, remote cache, etc. and different builder deployment/namespacing o
name: ci name: ci
on: on:
pull_request:
branches: master
push: push:
branches: master branches: master
tags:
jobs: jobs:
main: main:
@ -49,7 +48,7 @@ jobs:
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v1
- -
name: Login to DockerHub name: Login to DockerHub
uses: crazy-max/ghaction-docker-login@v1 # switch to docker/login-action@v1 when available uses: crazy-max/ghaction-docker-login@v1
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
@ -60,9 +59,7 @@ jobs:
with: with:
builder: ${{ steps.buildx.outputs.name }} builder: ${{ steps.buildx.outputs.name }}
push: true push: true
tags: | tags: user/app:latest
user/app:latest
user/app:1.0.0
- -
name: Image digest name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }} run: echo ${{ steps.docker_build.outputs.digest }}
@ -74,11 +71,8 @@ jobs:
name: ci name: ci
on: on:
pull_request:
branches: master
push: push:
branches: master branches: master
tags:
jobs: jobs:
multi: multi:
@ -98,7 +92,7 @@ jobs:
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v1
- -
name: Login to DockerHub name: Login to DockerHub
uses: crazy-max/ghaction-docker-login@v1 # switch to docker/login-action@v1 when available uses: crazy-max/ghaction-docker-login@v1
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
@ -107,6 +101,9 @@ jobs:
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
builder: ${{ steps.buildx.outputs.name }} builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/386
push: true push: true
tags: | tags: |
user/app:latest user/app:latest
@ -122,11 +119,8 @@ even in private repositories if your `context` is a valid Git url:
name: ci name: ci
on: on:
pull_request:
branches: master
push: push:
branches: master branches: master
tags:
jobs: jobs:
git-context: git-context:
@ -145,23 +139,96 @@ jobs:
version: latest version: latest
- -
name: Login to DockerHub name: Login to DockerHub
uses: crazy-max/ghaction-docker-login@v1 # switch to docker/login-action@v1 when available uses: crazy-max/ghaction-docker-login@v1
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
- -
name: Build and push name: Build and push
uses: ./ uses: docker/build-push-action@v2
env:
GIT_AUTH_TOKEN: ${{ github.token }}
with: with:
context: "${{ github.repositoryUrl }}#${{ github.ref }}"
builder: ${{ steps.buildx.outputs.name }} builder: ${{ steps.buildx.outputs.name }}
context: "${{ github.repositoryUrl }}#${{ github.ref }}"
platforms: linux/amd64,linux/arm64,linux/386 platforms: linux/amd64,linux/arm64,linux/386
push: true push: true
tags: | tags: |
name/app:latest name/app:latest
name/app:1.0.0 name/app:1.0.0
env:
GIT_AUTH_TOKEN: ${{ github.token }}
```
### Complete workflow
* On `pull_request` event, Docker image `name/app:edge` is **built**.
* On `push` event, Docker image `name/app:edge` is **built** and **pushed** to DockerHub.
* On `schedule` event, Docker image `name/app:nightly` is **built** and **pushed** to DockerHub.
* On `push tags` event, Docker image `name/app:<version>` and `name/app:latest` is **built** and **pushed** to DockerHub.
```yaml
name: ci
on:
schedule:
- cron: '0 10 * * *' # everyday at 10am
push:
branches: master
tags:
- 'v*.*.*'
pull_request:
branches: master
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Prepare
id: prep
run: |
DOCKER_IMAGE=name/app
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=tags::${TAGS}
-
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
-
name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: crazy-max/ghaction-docker-login@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/386
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
``` ```
## Customizing ## Customizing

View File

@ -22,7 +22,10 @@
], ],
"author": "Docker", "author": "Docker",
"contributors": [ "contributors": [
"CrazyMax" {
"name": "CrazyMax",
"url": "https://crazymax.dev"
}
], ],
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {