Skip to content

Commit 40e9431

Browse files
committed
add github actions
1 parent 8baa393 commit 40e9431

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

.github/workflows/docker.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Docker
2+
3+
# This will run when:
4+
# - a new release is created, to make sure the right tags of the
5+
# docker images are pushed (expects tags to be v1.8.4).
6+
# - when new code is pushed to master/develop to push the tags
7+
# latest and develop
8+
# - when a pull request is created and updated to make sure the
9+
# Dockerfile is still valid.
10+
# To be able to push to dockerhub, this execpts the following
11+
# secrets to be set in the project:
12+
# - DOCKERHUB_USERNAME : username that can push to the org
13+
# - DOCKERHUB_PASSWORD : password asscoaited with the username
14+
on:
15+
push:
16+
branches:
17+
- master
18+
19+
pull_request:
20+
21+
# Certain actions will only run when this is the master repo.
22+
env:
23+
MASTER_REPO: clowder-framework/extractors-clamav
24+
DOCKERHUB_ORG: clowder
25+
26+
jobs:
27+
docker:
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@v2
32+
33+
# calculate some variables that are used later
34+
- name: github branch
35+
run: |
36+
version="$(awk '/"version":/ { print $2 }' extractor_info.json | sed 's/^.*"\([0-9\.]*\)".*$/\1/')"
37+
echo "::set-env name=VERSION::${version}"
38+
tags="latest"
39+
oldversion=""
40+
while [ "${oldversion}" != "${version}" ]; do
41+
oldversion="${version}"
42+
tags="${tags},${version}"
43+
version=${version%.*}
44+
done
45+
echo "::set-env name=TAGS::${tags}"
46+
47+
# build the docker image, this will always run to make sure
48+
# the Dockerfile still works.
49+
- name: Build image
50+
run: |
51+
docker build --tag image .
52+
53+
# this will publish to the actor (person) github packages
54+
- name: Publish to GitHub
55+
if: github.event_name != 'pull_request'
56+
uses: elgohr/Publish-Docker-Github-Action@2.18
57+
env:
58+
VERSION: ${{ env.VERSION }}
59+
BUILDNUMBER: ${{ github.run_number }}
60+
GITSHA1: ${{ github.sha }}
61+
with:
62+
name: ${{ github.repository_owner }}/clowder/${{ github.event.repository.name }}
63+
username: ${{ github.actor }}
64+
password: ${{ secrets.GITHUB_TOKEN }}
65+
tags: "${{ env.TAGS }}"
66+
registry: docker.pkg.github.com
67+
buildargs: VERSION,BUILDNUMBER,GITSHA1
68+
69+
# this will publish to the clowder dockerhub repo
70+
- name: Publish to Docker Hub
71+
if: github.event_name != 'pull_request' && github.repository == env.MASTER_REPO
72+
uses: elgohr/Publish-Docker-Github-Action@2.18
73+
env:
74+
VERSION: ${{ env.VERSION }}
75+
BUILDNUMBER: ${{ github.run_number }}
76+
GITSHA1: ${{ github.sha }}
77+
with:
78+
name: ${{ env.DOCKERHUB_ORG }}/${{ github.event.repository.name }}
79+
username: ${{ secrets.DOCKERHUB_USERNAME }}
80+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
81+
tags: "${{ env.TAGS }}"
82+
buildargs: VERSION,BUILDNUMBER,GITSHA1
83+
84+
# this will update the README of the dockerhub repo
85+
- name: check file
86+
id: filecheck
87+
if: github.event_name != 'pull_request' && github.repository == env.MASTER_REPO
88+
run: |
89+
if [ -e "README" ]; then
90+
echo "##[set-output name=exists;]true"
91+
else
92+
echo "##[set-output name=exists;]false"
93+
fi
94+
- name: Docker Hub Description
95+
if: github.event_name != 'pull_request' && github.repository == env.MASTER_REPO && steps.filecheck.outputs.exists == 'true'
96+
uses: peter-evans/dockerhub-description@v2
97+
env:
98+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
99+
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
100+
DOCKERHUB_REPOSITORY: ${{ env.DOCKERHUB_ORG }}/${{ github.event.repository.name }}
101+
README_FILEPATH: README

0 commit comments

Comments
 (0)