From 3d0d7d3812b33963b9d04f2429ee7a8d5db469af Mon Sep 17 00:00:00 2001 From: Rob Chartier Date: Mon, 6 Jan 2025 19:34:25 -0800 Subject: [PATCH 1/3] first cut at a docker build workflow from main --- .github/workflows/docker_build_workflow.yml | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/docker_build_workflow.yml diff --git a/.github/workflows/docker_build_workflow.yml b/.github/workflows/docker_build_workflow.yml new file mode 100644 index 00000000..0b040b10 --- /dev/null +++ b/.github/workflows/docker_build_workflow.yml @@ -0,0 +1,38 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + # Checkout the repository code + - name: Checkout code + uses: actions/checkout@v3 + + # Log in to Docker Hub or GitHub Container Registry + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # Build the Docker image with multiple tags + - name: Build Docker image + run: | + GIT_HASH=$(git rev-parse --short=9 HEAD) + docker build -t ${{ secrets.DOCKER_USERNAME }}/my-image-name:latest -t ${{ secrets.DOCKER_USERNAME }}/my-image-name:$GIT_HASH . + + # Push the Docker image to the registry + - name: Push Docker image + run: | + GIT_HASH=$(git rev-parse --short=9 HEAD) + docker push ${{ secrets.DOCKER_USERNAME }}/my-image-name:latest + docker push ${{ secrets.DOCKER_USERNAME }}/my-image-name:$GIT_HASH From df25f971cb884dc3af3d36508d9bd314bb0c9dcc Mon Sep 17 00:00:00 2001 From: Rob Chartier Date: Mon, 6 Jan 2025 19:38:51 -0800 Subject: [PATCH 2/3] updated docker image name --- .github/workflows/docker_build_workflow.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker_build_workflow.yml b/.github/workflows/docker_build_workflow.yml index 0b040b10..64afbb1a 100644 --- a/.github/workflows/docker_build_workflow.yml +++ b/.github/workflows/docker_build_workflow.yml @@ -28,11 +28,11 @@ jobs: - name: Build Docker image run: | GIT_HASH=$(git rev-parse --short=9 HEAD) - docker build -t ${{ secrets.DOCKER_USERNAME }}/my-image-name:latest -t ${{ secrets.DOCKER_USERNAME }}/my-image-name:$GIT_HASH . + docker build -t ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:latest -t ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:$GIT_HASH . # Push the Docker image to the registry - name: Push Docker image run: | GIT_HASH=$(git rev-parse --short=9 HEAD) - docker push ${{ secrets.DOCKER_USERNAME }}/my-image-name:latest - docker push ${{ secrets.DOCKER_USERNAME }}/my-image-name:$GIT_HASH + docker push ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:latest + docker push ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:$GIT_HASH From 61ad9c3d0ca025f47cb4cfb0a680e62f29357e14 Mon Sep 17 00:00:00 2001 From: Drew Thomasson <126999465+DrewThomasson@users.noreply.github.com> Date: Mon, 20 Jan 2025 22:30:12 -0800 Subject: [PATCH 3/3] made it only build and push if conditions are met --- .github/workflows/docker_build_workflow.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker_build_workflow.yml b/.github/workflows/docker_build_workflow.yml index 64afbb1a..6807f2c5 100644 --- a/.github/workflows/docker_build_workflow.yml +++ b/.github/workflows/docker_build_workflow.yml @@ -1,16 +1,18 @@ name: Build and Push Docker Image on: - push: - branches: - - main - pull_request: - branches: - - main + workflow_run: + workflows: ["Run Ubuntu Headless ebook2audiobook"] + types: + - completed + release: + types: + - published # Trigger on release creation jobs: build: runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' && github.event_name == 'release' }} # Trigger if workflow passed and release published steps: # Checkout the repository code @@ -28,11 +30,11 @@ jobs: - name: Build Docker image run: | GIT_HASH=$(git rev-parse --short=9 HEAD) - docker build -t ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:latest -t ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:$GIT_HASH . + docker build -t ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:latest_small -t ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:$GIT_HASH . # Push the Docker image to the registry - name: Push Docker image run: | GIT_HASH=$(git rev-parse --short=9 HEAD) - docker push ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:latest + docker push ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:latest_small docker push ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:$GIT_HASH