From 5c3f64cb705b7bb7e725f184a98d6082b6cada32 Mon Sep 17 00:00:00 2001 From: Alex Bailey Date: Thu, 27 Feb 2025 14:43:25 +0000 Subject: [PATCH] GitHub Actions for pushing image to docker hub --- .github/workflows/build_main.yml | 24 +++++++++++++++++++ .github/workflows/build_tag.yml | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 .github/workflows/build_main.yml create mode 100644 .github/workflows/build_tag.yml diff --git a/.github/workflows/build_main.yml b/.github/workflows/build_main.yml new file mode 100644 index 0000000..8184f61 --- /dev/null +++ b/.github/workflows/build_main.yml @@ -0,0 +1,24 @@ +name: Build and Push latest image +on: + push: + branches: + - main +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and push Docker images + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ github.repository }}:latest \ No newline at end of file diff --git a/.github/workflows/build_tag.yml b/.github/workflows/build_tag.yml new file mode 100644 index 0000000..87e05f3 --- /dev/null +++ b/.github/workflows/build_tag.yml @@ -0,0 +1,41 @@ +name: Build and Push Release Docker Images +on: + push: + tags: + - 'v*' + workflow_dispatch: + +jobs: + build: + if: ${{ startsWith(github.ref, 'refs/tags/') }} + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Extract version parts + id: extract_version + run: | + VERSION=${GITHUB_REF#refs/tags/} + MAJOR_MINOR_PATCH=$(echo "$VERSION" | awk -F '-' '{print $1}') + MAJOR_MINOR=$(echo "$MAJOR_MINOR_PATCH" | awk -F '.' '{print $1"."$2}') + MAJOR=$(echo "$MAJOR_MINOR_PATCH" | awk -F '.' '{print $1}') + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "MAJOR_MINOR_PATCH=$MAJOR_MINOR_PATCH" >> $GITHUB_ENV + echo "MAJOR_MINOR=$MAJOR_MINOR" >> $GITHUB_ENV + echo "MAJOR=$MAJOR" >> $GITHUB_ENV + - name: Build and push Docker images + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + ${{ github.repository }}:${{ env.MAJOR_MINOR_PATCH }} + ${{ github.repository }}:release-${{ env.MAJOR_MINOR }} + ${{ github.repository }}:${{ env.MAJOR }}-latest \ No newline at end of file