|
1 | | -name: Deploy Docker image to GitHub Container Registry and Docker Hub |
| 1 | +name: Build and Deploy Docker Images |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - tags: |
6 | | - - 'v*' # Trigger on any tag that starts with 'v' |
7 | | - branches: |
8 | | - - main # Trigger on push to main branch |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + ref: |
| 7 | + description: Git Ref |
| 8 | + required: true |
| 9 | + type: string |
9 | 10 |
|
10 | 11 | jobs: |
11 | | - docker: |
| 12 | + build: |
| 13 | + name: build |
12 | 14 | runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + packages: write |
| 17 | + contents: read |
13 | 18 | steps: |
14 | | - # Checkout the repository |
15 | | - - name: Checkout repository |
| 19 | + - name: Checkout |
16 | 20 | uses: actions/checkout@v4 |
17 | | - |
18 | | - # Set up QEMU for multi-platform builds |
19 | | - - name: Set up QEMU |
20 | | - uses: docker/setup-qemu-action@v3 |
21 | | - |
22 | | - # Set up Docker Buildx |
23 | | - - name: Set up Docker Buildx |
24 | | - uses: docker/setup-buildx-action@v3 |
25 | | - |
26 | | - # Log in to GitHub Container Registry (GHCR) |
27 | | - - name: Log in to GitHub Container Registry |
28 | | - uses: docker/login-action@v3 |
29 | 21 | with: |
30 | | - registry: ghcr.io |
31 | | - username: ${{ github.actor }} |
32 | | - password: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + fetch-depth: 0 |
| 23 | + ref: ${{inputs.ref}} |
| 24 | + token: ${{ secrets.GITHUB_TOKEN }} |
33 | 25 |
|
34 | | - # Log in to Docker Hub |
35 | | - - name: Log in to Docker Hub |
36 | | - if: startsWith(github.ref, 'refs/tags/v') |
| 26 | + - name: Login to Docker Hub |
37 | 27 | uses: docker/login-action@v3 |
38 | 28 | with: |
39 | 29 | username: ${{ secrets.DOCKERHUB_USERNAME }} |
40 | 30 | password: ${{ secrets.DOCKERHUB_TOKEN }} |
41 | 31 |
|
42 | | - # Build and push Docker image to both GHCR and Docker Hub |
43 | | - - name: Build and push Docker image (tags) |
44 | | - if: startsWith(github.ref, 'refs/tags/v') |
45 | | - uses: docker/build-push-action@v6 |
| 32 | + - name: Login to GitHub Container Registry |
| 33 | + uses: docker/login-action@v3 |
46 | 34 | with: |
47 | | - platforms: linux/amd64,linux/arm64 |
48 | | - push: true |
49 | | - tags: | |
50 | | - ghcr.io/viren070/aiostreams:${{ github.ref_name }} |
51 | | - ghcr.io/viren070/aiostreams:latest |
52 | | - docker.io/${{ secrets.DOCKERHUB_USERNAME }}/aiostreams:${{ github.ref_name }} |
53 | | - docker.io/${{ secrets.DOCKERHUB_USERNAME }}/aiostreams:latest |
54 | | -
|
55 | | - # Build and push Docker image to GHCR only for each commit to main branch |
56 | | - - name: Build and push Docker image (dev) |
57 | | - if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 35 | + registry: ghcr.io |
| 36 | + username: ${{ github.repository_owner }} |
| 37 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + |
| 39 | + - name: Set up QEMU |
| 40 | + uses: docker/setup-qemu-action@v3 |
| 41 | + |
| 42 | + - name: Set up Buildx |
| 43 | + uses: docker/setup-buildx-action@v3 |
| 44 | + |
| 45 | + - name: Calculate Image Tags |
| 46 | + env: |
| 47 | + INPUT_REF: ${{inputs.ref}} |
| 48 | + run: | |
| 49 | + declare TAGS="" |
| 50 | + case "${INPUT_REF}" in |
| 51 | + v[0-9]*.[0-9]*.[0-9]*) |
| 52 | + TAGS="${INPUT_REF}" |
| 53 | + if [[ "$(git rev-parse origin/main)" = "$(git rev-parse "${INPUT_REF}")" ]]; then |
| 54 | + TAGS="${TAGS} latest" |
| 55 | + fi |
| 56 | + ;; |
| 57 | + [0-9]*.[0-9]*.[0-9]*-nightly) |
| 58 | + TAGS="${INPUT_REF} nightly" |
| 59 | + ;; |
| 60 | + *) |
| 61 | + echo "Invalid Input Ref: ${INPUT_REF}" |
| 62 | + exit 1 |
| 63 | + esac |
| 64 | +
|
| 65 | + if [[ -z "${TAGS}" ]]; then |
| 66 | + echo "Empty Tags!" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | +
|
| 70 | + { |
| 71 | + echo 'DOCKER_IMAGE_TAGS<<EOF' |
| 72 | + for tag in ${TAGS}; do |
| 73 | + echo "viren070/aiostreams:${tag}" |
| 74 | + echo "ghcr.io/viren070/aiostreams:${tag}" |
| 75 | + done |
| 76 | + echo EOF |
| 77 | + } >> "${GITHUB_ENV}" |
| 78 | +
|
| 79 | + cat "${GITHUB_ENV}" |
| 80 | +
|
| 81 | + - name: Build & Push |
58 | 82 | uses: docker/build-push-action@v6 |
59 | 83 | with: |
| 84 | + cache-from: type=gha |
| 85 | + cache-to: type=gha,mode=max |
60 | 86 | platforms: linux/amd64,linux/arm64 |
61 | 87 | push: true |
62 | | - tags: ghcr.io/viren070/aiostreams:dev |
| 88 | + context: . |
| 89 | + file: ./Dockerfile |
| 90 | + tags: ${{env.DOCKER_IMAGE_TAGS}} |
0 commit comments