/ opencodehub / .github / workflows / docker-publish.yml
swadhinbiswas feat: optimize Docker CI/CD builds, refine site-wide UI aesthetic, and remediate secrets · 8/19/2026
c3e5c18
122 lines · 4.1 KB
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
114
115
116
117
118
119
120
121
122
name: Build & Push Docker Image

on:
  push:
    branches: [main]
    tags: ["v*"]
  workflow_dispatch:
    inputs:
      platforms:
        description: "Platforms to build (e.g. linux/amd64,linux/arm64 or linux/amd64)"
        required: false
        default: "linux/amd64"
        type: string

env:
  REGISTRY: docker.io
  IMAGE_BASE: opencodehub/opencodehub

jobs:
  build-and-push:
    name: Build & Push (${{ matrix.target.name }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        target:
          - name: app
            file: ./Dockerfile
            suffix: ""
            title: "OpenCodeHub Platform"
            desc: "A modern, self-hosted Git platform with stacked PRs, merge queue, CI/CD, and AI review."
          - name: worker
            file: ./Dockerfile.worker
            suffix: "-worker"
            title: "OpenCodeHub Worker"
            desc: "Background task worker for OpenCodeHub (queues, webhooks, notifications)."
          - name: runner
            file: ./Dockerfile.runner
            suffix: "-runner"
            title: "OpenCodeHub Runner"
            desc: "Docker-in-Docker CI/CD runner for OpenCodeHub pipelines."

    permissions:
      contents: read
      packages: write

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Determine platforms
        id: platforms
        run: |
          if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.platforms }}" ]; then
            echo "platforms=${{ github.event.inputs.platforms }}" >> $GITHUB_OUTPUT
          elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
            echo "platforms=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT
          else
            echo "platforms=linux/amd64" >> $GITHUB_OUTPUT
          fi

      - name: Set up QEMU (only when multi-arch requested)
        if: contains(steps.platforms.outputs.platforms, 'arm64')
        uses: docker/setup-qemu-action@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log in to DockerHub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}

      - name: Extract Metadata
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}${{ matrix.target.suffix }}
          tags: |
            type=ref,event=branch
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
            type=sha,prefix=
            type=raw,value=latest,enable={{is_default_branch}}
          labels: |
            org.opencontainers.image.title=${{ matrix.target.title }}
            org.opencontainers.image.description=${{ matrix.target.desc }}
            org.opencontainers.image.url=https://github.com/swadhinbiswas/OpencodeHub
            org.opencontainers.image.source=https://github.com/swadhinbiswas/OpencodeHub
            org.opencontainers.image.licenses=MIT

      - name: Build and Push Image
        uses: docker/build-push-action@v5
        with:
          context: .
          file: ${{ matrix.target.file }}
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha,scope=${{ matrix.target.name }}
          cache-to: type=gha,mode=max,scope=${{ matrix.target.name }}
          platforms: ${{ steps.platforms.outputs.platforms }}

  update-dockerhub-desc:
    name: Update DockerHub Description
    runs-on: ubuntu-latest
    needs: build-and-push
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Update Docker Hub Description
        uses: peter-evans/dockerhub-description@v4
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}
          repository: ${{ env.IMAGE_BASE }}
          readme-filepath: ./DOCKERHUB.md
          short-description: "Self-hosted Git platform with stacked PRs, merge queue, CI/CD, and AI code review"