-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add workflow for docker publishing to dockerhub (#73)
* add workflow for docker publishing to dockerhub Co-authored-by: Mike Ivanov <[email protected]>
- Loading branch information
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
name: Docker | ||
|
||
on: | ||
|
||
# Publish releases as 'latest'. | ||
release: | ||
types: [published] | ||
|
||
push: | ||
# Publish `master` as Docker `master-latest` image | ||
# Publish for any branch as well | ||
branches: | ||
- master | ||
- '*' | ||
|
||
# Publish `v1.2.3` tags as releases. | ||
tags: | ||
- 'v*' | ||
|
||
# Run tests for any PRs. | ||
pull_request: | ||
|
||
|
||
env: | ||
IMAGE: cluster.dev | ||
REGISTRY: docker.io/clusterdev | ||
|
||
jobs: | ||
# Run tests | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Run tests | ||
run: docker build . | ||
|
||
# Push image to Docker Hub | ||
push: | ||
# Ensure test job passes before pushing image. | ||
needs: test | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Build image | ||
run: docker build -t $IMAGE . | ||
|
||
- name: Log into registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login --username "${{ secrets.DOCKER_USER }}" --password "${{ secrets.DOCKER_PASS }}" | ||
|
||
|
||
- name: Push image for release | ||
if: github.event_name == 'release' | ||
run: | | ||
# Strip git ref prefix from version | ||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | ||
# Strip "v" prefix from tag name | ||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo "$VERSION" | sed -e 's/^v//') | ||
# Use Docker `latest` tag convention | ||
[ "$VERSION" == "master" ] && VERSION=latest | ||
echo IMAGE=$IMAGE | ||
echo VERSION=$VERSION | ||
docker tag "$IMAGE" "$REGISTRY/$IMAGE:$VERSION" | ||
docker push "$REGISTRY/$IMAGE:$VERSION" | ||
docker tag "$IMAGE" "$REGISTRY/$IMAGE:latest" | ||
docker push "$REGISTRY/$IMAGE:latest" | ||
- name: Push image for master branch | ||
if: github.event_name == 'push' && github.ref == 'refs/heads/master' | ||
run: | | ||
VERSION="master-latest" | ||
echo IMAGE=$IMAGE | ||
echo VERSION=$VERSION | ||
docker tag "$IMAGE" "$REGISTRY/$IMAGE:$VERSION-${GITHUB_SHA}" | ||
docker push "$REGISTRY/$IMAGE:$VERSION-${GITHUB_SHA}" | ||
- name: Push image for other branch | ||
if: github.event_name == 'push' && github.ref != 'refs/heads/master' | ||
run: | | ||
#Get branch name | ||
VERSION=${GITHUB_REF#refs/heads/} | ||
echo IMAGE_ID=$IMAGE | ||
echo VERSION=$VERSION | ||
docker tag "$IMAGE" "$REGISTRY/$IMAGE:$VERSION-${GITHUB_SHA}" | ||
docker push "$REGISTRY/$IMAGE:$VERSION-${GITHUB_SHA}" |