-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
64 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,64 @@ | ||
name: Docker | ||
on: [push] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- name: Prepare | ||
id: prepare | ||
run: | | ||
if [[ $GITHUB_REF == refs/tags/* ]]; then | ||
echo ::set-output name=version::${GITHUB_REF#refs/tags/v} | ||
elif [[ $GITHUB_REF == refs/heads/master ]]; then | ||
echo ::set-output name=version::latest | ||
elif [[ $GITHUB_REF == refs/heads/* ]]; then | ||
echo ::set-output name=version::${GITHUB_REF#refs/heads/} | ||
else | ||
echo ::set-output name=version::snapshot | ||
fi | ||
echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ') | ||
echo ::set-output name=docker_platforms::linux/amd64,linux/arm/v7 | ||
echo ::set-output name=docker_image::${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }} | ||
# https://github.com/crazy-max/ghaction-docker-buildx | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: crazy-max/ghaction-docker-buildx@v1 | ||
with: | ||
version: latest | ||
|
||
- name: Environment | ||
run: | | ||
echo home=$HOME | ||
echo git_ref=$GITHUB_REF | ||
echo git_sha=$GITHUB_SHA | ||
echo version=${{ steps.prepare.outputs.version }} | ||
echo date=${{ steps.prepare.outputs.build_date }} | ||
echo image=${{ steps.prepare.outputs.docker_image }} | ||
echo platforms=${{ steps.prepare.outputs.docker_platforms }} | ||
echo avail_platforms=${{ steps.buildx.outputs.platforms }} | ||
# https://github.com/actions/checkout | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Docker Login | ||
if: success() | ||
env: | ||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | ||
run: | | ||
echo "${DOCKER_PASSWORD}" | docker login --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin | ||
- name: Docker Buildx (push) | ||
if: success() | ||
run: | | ||
docker buildx build \ | ||
--platform ${{ steps.prepare.outputs.docker_platforms }} \ | ||
--output "type=image,push=true" \ | ||
--build-arg "VERSION=${{ steps.prepare.outputs.version }}" \ | ||
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \ | ||
--build-arg "VCS_REF=${GITHUB_SHA}" \ | ||
--tag "${{ steps.prepare.outputs.docker_image }}:${GITHUB_SHA}" \ | ||
--tag "${{ steps.prepare.outputs.docker_image }}:latest" \ | ||
--file Dockerfile . | ||
- name: Clear | ||
if: always() | ||
run: | | ||
rm -f ${HOME}/.docker/config.json |