name: Docker Build on: [push] jobs: docker-build: runs-on: ubuntu-latest services: registry: image: registry:2 ports: - '5000:5000' env: DOCKER_BUILDKIT: 1 DOCKER_CLI_EXPERIMENTAL: enabled steps: - name: enable experimental mode run: | mkdir -p ~/.docker echo '{"experimental": "enabled"}' > ~/.docker/config.json - name: Set up QEMU uses: docker/setup-qemu-action@v1.2.0 - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1.6.0 with: version: v0.5.1 driver-opts: | image=moby/buildkit:buildx-stable-1 network=host - name: Available platforms run: echo {{ `${{ steps.buildx.outputs.platforms }}` }} - run: docker info && docker version - uses: actions/checkout@v2 with: fetch-depth: 0 - name: determine if this is a tag run: | if (git describe --abbrev=0 --exact-match &>/dev/null); then tag=$(git describe --abbrev=0 --exact-match) echo "is_tag=true" >> $GITHUB_ENV echo "git_tag=$tag" >> $GITHUB_ENV # splits the major version from $tag - assumes it's a 3-part semver echo "major_version=${tag%%\.*}" >> $GITHUB_ENV fi echo $GITHUB_ENV if: github.repository == 'hairyhenderson/gomplate' - name: Build & Push (non-master) run: | set -ex make docker-multi COMMIT=${{ github.sha }} DOCKER_REPO=localhost:5000/gomplate BUILDX_ACTION=--push docker buildx imagetools create --dry-run -t localhost:5000/gomplate:dev localhost:5000/gomplate:latest docker buildx imagetools create --dry-run -t localhost:5000/gomplate:dev-slim localhost:5000/gomplate:slim docker buildx imagetools create --dry-run -t localhost:5000/gomplate:dev-alpine localhost:5000/gomplate:alpine if: github.repository != 'hairyhenderson/gomplate' || (github.ref != 'refs/heads/master' && env.is_tag != 'true') - name: Login to GHCR uses: docker/login-action@v1.14.1 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} if: github.repository == 'hairyhenderson/gomplate' && (github.ref == 'refs/heads/master' || env.is_tag == 'true') - name: Login to DockerHub uses: docker/login-action@v1.14.1 with: # NOTE: DOCKERHUB_TOKEN and DOCKERHUB_USERNAME must be present in https://github.com/hairyhenderson/gomplate/settings username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} if: github.repository == 'hairyhenderson/gomplate' && (github.ref == 'refs/heads/master' || env.is_tag == 'true') - name: Build & Push (master) run: | make docker-multi COMMIT=${{ github.sha }} DOCKER_REPO=hairyhenderson/gomplate BUILDX_ACTION=--push make docker-multi COMMIT=${{ github.sha }} DOCKER_REPO=ghcr.io/hairyhenderson/gomplate BUILDX_ACTION=--push if: github.repository == 'hairyhenderson/gomplate' && github.ref == 'refs/heads/master' - name: Build & Push (tagged release) run: | make docker-multi COMMIT=${{ github.sha }} DOCKER_REPO=hairyhenderson/gomplate BUILDX_ACTION=--push make docker-multi COMMIT=${{ github.sha }} DOCKER_REPO=ghcr.io/hairyhenderson/gomplate BUILDX_ACTION=--push set -x repo=hairyhenderson/gomplate docker buildx imagetools create -t ${repo}:stable ${repo}:latest docker buildx imagetools create -t ${repo}:${git_tag} ${repo}:latest docker buildx imagetools create -t ${repo}:${major_version} ${repo}:latest docker buildx imagetools create -t ${repo}:stable-slim ${repo}:slim docker buildx imagetools create -t ${repo}:${git_tag}-slim ${repo}:slim docker buildx imagetools create -t ${repo}:${major_version}-slim ${repo}:slim docker buildx imagetools create -t ${repo}:stable-alpine ${repo}:alpine docker buildx imagetools create -t ${repo}:${git_tag}-alpine ${repo}:alpine docker buildx imagetools create -t ${repo}:${major_version}-alpine ${repo}:alpine # and now GHCR repo=ghcr.io/hairyhenderson/gomplate docker buildx imagetools create -t ${repo}:stable ${repo}:latest docker buildx imagetools create -t ${repo}:${git_tag} ${repo}:latest docker buildx imagetools create -t ${repo}:${major_version} ${repo}:latest docker buildx imagetools create -t ${repo}:stable-slim ${repo}:slim docker buildx imagetools create -t ${repo}:${git_tag}-slim ${repo}:slim docker buildx imagetools create -t ${repo}:${major_version}-slim ${repo}:slim docker buildx imagetools create -t ${repo}:stable-alpine ${repo}:alpine docker buildx imagetools create -t ${repo}:${git_tag}-alpine ${repo}:alpine docker buildx imagetools create -t ${repo}:${major_version}-alpine ${repo}:alpine if: github.repository == 'hairyhenderson/gomplate' && env.is_tag == 'true'