diff options
| author | Haishan <[email protected]> | 2019-11-09 14:52:28 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2019-11-09 14:53:59 +0800 |
| commit | 3003876bb6620fb18ccd4aa5c5b05829fc3f1d71 (patch) | |
| tree | ab1a88d45150fd01e8a577f4c80c61ec0d912470 | |
| parent | 4aa9d0808f46852026b557e3a0372c9648ef409e (diff) | |
build: gh actions workflows for push docker image
| -rw-r--r-- | .github/workflows/docker-push.yml | 62 | ||||
| -rw-r--r-- | .github/workflows/push.yml | 59 | ||||
| -rw-r--r-- | .gitignore | 1 |
3 files changed, 94 insertions, 28 deletions
diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml new file mode 100644 index 0000000..f4c197d --- /dev/null +++ b/.github/workflows/docker-push.yml @@ -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 diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index b58583f..84866c4 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,4 +1,7 @@ -on: [push] +on: + push: + tags: + - '*' name: Deploy workflow @@ -11,33 +14,33 @@ jobs: node-version: [12.x] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v1 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} - - name: Install Lint Build - run: | - yarn - yarn lint - yarn build + - name: Install Lint Build + run: | + yarn + yarn lint + yarn build - - name: Push to gh-pages - # push only when the branch is publish - if: github.event_name == 'push' && github.event.ref == 'refs/heads/publish' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PUBLISH_DIR: public - BRANCH: gh-pages - run: | - cd $PUBLISH_DIR - ls -l - git init - git config user.name "${GITHUB_ACTOR}" - git config user.email "${GITHUB_ACTOR}@noreply.github.com" - git add . - git status - git commit -m "Push to gh-pages" - git push -f https://$GITHUB_ACTOR:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:$BRANCH + - name: Push to gh-pages + # push only when the branch is publish + # if: github.event_name == 'push' && github.event.ref == 'refs/heads/publish' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PUBLISH_DIR: public + BRANCH: gh-pages + run: | + cd $PUBLISH_DIR + ls -l + git init + git config user.name "${GITHUB_ACTOR}" + git config user.email "${GITHUB_ACTOR}@noreply.github.com" + git add . + git status + git commit -m "Push to gh-pages" + git push -f https://$GITHUB_ACTOR:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:$BRANCH @@ -6,3 +6,4 @@ experimental/ deploy_ghpages.sh tags *.log +!.github |
