build: gh actions workflows for push docker image

This commit is contained in:
Haishan 2019-11-09 14:52:28 +08:00
parent 4aa9d0808f
commit 3003876bb6
3 changed files with 94 additions and 28 deletions

62
.github/workflows/docker-push.yml vendored Normal file
View file

@ -0,0 +1,62 @@
# require the secrets DOCKER_HUB_PASSWORD
name: Docker Push
on:
push:
branches:
- master
tags:
- '*'
env:
IMAGE_NAME: yacd
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile
fi
push:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v1
- name: Build image
run: docker build . --file Dockerfile --tag image
- name: Log into registry
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ github.actor }} --password-stdin
- name: Push image
run: |
IMAGE_ID=haishanh/$IMAGE_NAME
# 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_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION

View file

@ -1,4 +1,7 @@
on: [push] on:
push:
tags:
- '*'
name: Deploy workflow name: Deploy workflow
@ -26,7 +29,7 @@ jobs:
- name: Push to gh-pages - name: Push to gh-pages
# push only when the branch is publish # push only when the branch is publish
if: github.event_name == 'push' && github.event.ref == 'refs/heads/publish' # if: github.event_name == 'push' && github.event.ref == 'refs/heads/publish'
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_DIR: public PUBLISH_DIR: public

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ experimental/
deploy_ghpages.sh deploy_ghpages.sh
tags tags
*.log *.log
!.github