summaryrefslogtreecommitdiff
path: root/.github/workflows/docker.yml
blob: 44ceedd65e814578c989c830ad0c9ee22835f4f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Docker Build
on:
  push:
    branches: [ main ]
    tags: [ 'v*', '!v*-pre*']
  pull_request:
    branches: [ main ]
  workflow_dispatch:

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@v3.0.0
    - name: Set up Docker Buildx
      id: buildx
      uses: docker/setup-buildx-action@v3.1.0
      with:
        version: v0.11.2
        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@v4
      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-main)
      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-alpine localhost:5000/gomplate:alpine
      if: github.repository != 'hairyhenderson/gomplate' || (github.ref != 'refs/heads/main' && env.is_tag != 'true')
    - name: Login to GHCR
      uses: docker/login-action@v3.1.0
      with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      if: github.repository == 'hairyhenderson/gomplate' && (github.ref == 'refs/heads/main' || env.is_tag == 'true')
    - name: Login to DockerHub
      uses: docker/login-action@v3.1.0
      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/main' || env.is_tag == 'true')
    - name: Build & Push (main)
      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/main'
    - name: Build & Push (tagged release)
      run: |
        export srcrepo=hairyhenderson/gomplate
        make docker-multi COMMIT=${{ github.sha }} DOCKER_REPO=hairyhenderson/gomplate BUILDX_ACTION=--push

        set -x
        export repo=hairyhenderson/gomplate
        docker buildx imagetools create -t ${repo}:stable ${srcrepo}:latest
        docker buildx imagetools create -t ${repo}:${git_tag} ${srcrepo}:latest
        docker buildx imagetools create -t ${repo}:${major_version} ${srcrepo}:latest

        docker buildx imagetools create -t ${repo}:stable-alpine ${srcrepo}:alpine
        docker buildx imagetools create -t ${repo}:${git_tag}-alpine ${srcrepo}:alpine
        docker buildx imagetools create -t ${repo}:${major_version}-alpine ${srcrepo}:alpine

        export repo=gomplate/gomplate
        docker buildx imagetools create -t ${repo}:stable ${srcrepo}:latest
        docker buildx imagetools create -t ${repo}:${git_tag} ${srcrepo}:latest
        docker buildx imagetools create -t ${repo}:${major_version} ${srcrepo}:latest

        docker buildx imagetools create -t ${repo}:stable-alpine ${srcrepo}:alpine
        docker buildx imagetools create -t ${repo}:${git_tag}-alpine ${srcrepo}:alpine
        docker buildx imagetools create -t ${repo}:${major_version}-alpine ${srcrepo}:alpine

        # and now GHCR
        export repo=ghcr.io/hairyhenderson/gomplate
        docker buildx imagetools create -t ${repo}:stable ${srcrepo}:latest
        docker buildx imagetools create -t ${repo}:${git_tag} ${srcrepo}:latest
        docker buildx imagetools create -t ${repo}:${major_version} ${srcrepo}:latest

        docker buildx imagetools create -t ${repo}:stable-alpine ${srcrepo}:alpine
        docker buildx imagetools create -t ${repo}:${git_tag}-alpine ${srcrepo}:alpine
        docker buildx imagetools create -t ${repo}:${major_version}-alpine ${srcrepo}:alpine
      if: github.repository == 'hairyhenderson/gomplate' && env.is_tag == 'true'