Skip to content

Commit

Permalink
Updating docker workflows
Browse files Browse the repository at this point in the history
* Allowing docker builds on branches -> useful for testing
* Adding delete docker image workflow for when a branch not main is deleted
  • Loading branch information
Carolyn Russell committed Apr 8, 2021
1 parent 4888dde commit 18e8e30
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/docker-branch-delete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Delete branch docker
# Deletes the docker associated with the branch

on:
delete:
branches:
- '!main'

jobs:
delete:
if: github.event.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Clean up
run: echo "Clean up for branch ${{ github.event.ref }}"
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=provenanceio/explorer-service
VERSION=$(echo ${github.event.ref} | sed -r 's#/+#-#g')
echo ::set-output name=version::${VERSION}
- name: Delete branch docker
uses: m3ntorship/[email protected]
id: delete_old_tags
with:
token: ${{secrets.DOCKERHUB_TOKEN}}
keep-last: 50
user: ${{ secrets.DOCKERHUB_USERNAME }}
repos: '["provenanceio/explorer-service"]'
substrings: '[${{ steps.prep.outputs.version }}]'
31 changes: 27 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: Build
name: Docker

on:
push:
branches: [ main ]
branches:
- '**'

jobs:
build:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -23,6 +24,27 @@ jobs:
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=provenanceio/explorer-service
VERSION=noop
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
echo ::set-output name=branch::${VERSION}
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=latest
fi
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
Expand All @@ -36,9 +58,10 @@ jobs:
file: docker/Dockerfile-service
context: .
push: true
tags: provenanceio/explorer-service:latest
tags: ${{ steps.prep.outputs.tags }}
- name: Build and push database docker
uses: docker/build-push-action@v2
if: ${{ steps.prep.outputs.branch == github.event.repository.default_branch }}
with:
file: docker/Dockerfile-database
context: .
Expand Down

0 comments on commit 18e8e30

Please sign in to comment.