Skip to content

Commit

Permalink
chore: docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
Larvan2 committed Sep 22, 2023
1 parent 41f3fb0 commit a15dd40
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 228 deletions.
255 changes: 28 additions & 227 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Publish Docker Image
on:
on:
push:
branches: [ master ]
branches: [master]

concurrency:
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

Expand All @@ -20,11 +20,12 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker login
uses: docker/login-action@v2
- name: login to ghcr.io
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get commit SHA
id: vars
Expand All @@ -37,38 +38,15 @@ jobs:
with:
platforms: linux/amd64
context: scripts/
tags: tindy2013/subconverter:latest
tags: ghcr.io/metacubex/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
outputs: type=image,push=true

- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v6
id: version
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string

- name: Build release and export
id: build_rel
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
platforms: linux/amd64
context: scripts/
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
outputs: type=image,push=true

- name: Save digest
if: github.ref == 'refs/heads/master'
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt

- name: Save release digest
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ steps.build_rel.outputs.digest }} > /tmp/digest.txt

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
Expand All @@ -87,11 +65,12 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker login
uses: docker/login-action@v2
- name: login to ghcr.io
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get commit SHA
id: vars
Expand All @@ -104,120 +83,24 @@ jobs:
with:
platforms: linux/386
context: scripts/
tags: tindy2013/subconverter:latest
tags: ghcr.io/metacubex/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
outputs: type=image,push=true

- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v6
id: version
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string

- name: Build release and export
id: build_rel
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
platforms: linux/386
context: scripts/
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
outputs: type=image,push=true

- name: Save digest
if: github.ref == 'refs/heads/master'
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt

- name: Save release digest
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ steps.build_rel.outputs.digest }} > /tmp/digest.txt

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: digest_386
path: /tmp/digest.txt

armv7_build:
name: Build ARMv7 Image
runs-on: [self-hosted, linux, ARM64]
steps:
- name: Checkout base
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get commit SHA
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

- name: Build and export
id: build
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v3
with:
platforms: linux/arm/v7
context: scripts/
tags: tindy2013/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
THREADS=2
outputs: type=image,push=true

- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v6
id: version
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string

- name: Build release and export
id: build_rel
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
platforms: linux/arm/v7
context: scripts/
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
build-args: |
THREADS=2
outputs: type=image,push=true

- name: Save digest
if: github.ref == 'refs/heads/master'
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt

- name: Save release digest
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ steps.build_rel.outputs.digest }} > /tmp/digest.txt

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: digest_armv7
path: /tmp/digest.txt

arm64_build:
name: Build ARM64 Image
runs-on: [self-hosted, linux, ARM64]
runs-on: ubuntu-latest
steps:
- name: Checkout base
uses: actions/checkout@v3
Expand All @@ -230,11 +113,12 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker login
uses: docker/login-action@v2
- name: login to ghcr.io
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get commit SHA
id: vars
Expand All @@ -247,50 +131,24 @@ jobs:
with:
platforms: linux/arm64
context: scripts/
tags: tindy2013/subconverter:latest
tags: ghcr.io/metacubex/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
THREADS=2
outputs: type=image,push=true

- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v6
id: version
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string

- name: Build release and export
id: build_rel
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
platforms: linux/arm64
context: scripts/
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
build-args: |
THREADS=2
outputs: type=image,push=true

- name: Save digest
if: github.ref == 'refs/heads/master'
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt

- name: Save release digest
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ steps.build_rel.outputs.digest }} > /tmp/digest.txt

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: digest_arm64
path: /tmp/digest.txt

build:
name: Build
needs: [amd64_build, x86_build, armv7_build, arm64_build]
needs: [amd64_build, x86_build, arm64_build]
runs-on: ubuntu-latest
steps:
- name: Checkout base
Expand All @@ -315,70 +173,13 @@ jobs:
with:
path: /tmp/images/

# - name: Load image
# if: github.ref == 'refs/heads/master'
# run: |
# docker load --input /tmp/image_amd64/image_amd64.tar
# docker load --input /tmp/image_386/image_386.tar
# docker load --input /tmp/image_armv7/image_armv7.tar
# docker load --input /tmp/image_arm64/image_arm64.tar
# docker image ls -a

- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# - name: Get commit SHA
# id: vars
# run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

# - name: Docker buildx image and push on master branch
# if: github.ref == 'refs/heads/master'
# uses: docker/build-push-action@v3
# with:
# platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/386
# context: scripts/
# tags: tindy2013/subconverter:latest
# build-args: |
# SHA=${{ steps.vars.outputs.sha_short }}
# THREADS=1
# outputs: |
# type=image,push=true

- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v6
id: version
- name: login to ghcr.io
uses: docker/login-action@v3
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string

# - name: Load release image
# if: startsWith(github.ref, 'refs/tags/')
# run: |
# docker load --input /tmp/image_amd64/image_amd64_release.tar
# docker load --input /tmp/image_386/image_386_release.tar
# docker load --input /tmp/image_armv7/image_armv7_release.tar
# docker load --input /tmp/image_arm64/image_arm64_release.tar
# docker image ls -a

# - name: Docker buildx image and push on release
# if: startsWith(github.ref, 'refs/tags/')
# uses: docker/build-push-action@v3
# with:
# platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/386
# context: scripts/
# tags: tindy2013/subconverter:${{steps.version.outputs.result}}
# build-args: THREADS=1
# outputs: type=image,push=true
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Merge and push manifest on master branch
if: github.ref == 'refs/heads/master'
run: python scripts/merge_manifest.py

- name: Merge and push manifest on release
if: startsWith(github.ref, 'refs/tags/')
run: python scripts/merge_manifest.py ${{steps.version.outputs.result}}
2 changes: 1 addition & 1 deletion scripts/merge_manifest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import glob
import os, sys

MAIN_IMAGE_NAME="tindy2013/subconverter"
MAIN_IMAGE_NAME="ghcr.io/MetaCubeX/subconverter"
TARGET_TAG="latest" if len(sys.argv) < 2 else sys.argv[1]

args=["docker manifest create {}:{}".format(MAIN_IMAGE_NAME, TARGET_TAG)]
Expand Down

0 comments on commit a15dd40

Please sign in to comment.