From 80b93fe0e1f4bb8db699bf96276487e60fb50ab8 Mon Sep 17 00:00:00 2001 From: Yamel Senih Date: Thu, 28 Oct 2021 12:11:56 -0400 Subject: [PATCH] Create docker-image.yml --- .github/workflows/docker-image.yml | 106 +++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..4cf40ba --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,106 @@ +# This workflow will run tests using node and then publish a package to GitHub Container Registry and Docker Hub Regitry when a pushed into main branches +# This file was contributed by EdwinBetanc0urt@outlook.com from ERP Consultores y Asociados, C.A + +name: Push Main Branches + +on: + # Triggers the workflow on push events but only for the develop branch + push: + branches: + - master + - alpine + release: + types: + - published + +jobs: + + # Publish docker image in Github Container Registry to application + push-imame-ghcr: + name: Push Docker image to GitHub Container + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set Lower Case to owner and repository + run: | + echo "OWNER_LC=${OWNER,,}" >> ${GITHUB_ENV} + echo "REPO_LC=${NAME,,}" >> ${GITHUB_ENV} + env: + OWNER: '${{ github.repository_owner }}' + NAME: '${{ github.event.repository.name }}' + + - name: Get branch name + id: branch-name + uses: tj-actions/branch-names@v4.8 + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + push: true + tags: | + ghcr.io/${{ env.OWNER_LC }}/${{ env.REPO_LC }}:${{ steps.branch-name.outputs.current_branch }} + ghcr.io/${{ env.OWNER_LC }}/${{ env.REPO_LC }}:${{ github.sha }} + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + + + # Publish docker image in Docker Hub registry to application + push-imame-dhr: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + # CONFIGURE DOCKER SECRETS INTO REPOSITORY + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set Lower Case to owner and repository + run: | + ORG=$OWNER + if [ -n "${{ secrets.DOCKERHUB_ORG }}" ]; then + echo "Set secret DOCKERHUB_ORG as namespace" + ORG=${{ secrets.DOCKERHUB_ORG }} + else + echo "Set OWNER ($OWNER) as namespace " + fi + echo "ORG_LC=${ORG,,}" >> ${GITHUB_ENV} + echo "OWNER_LC=${OWNER,,}" >> ${GITHUB_ENV} + echo "REPO_LC=${NAME,,}" >> ${GITHUB_ENV} + env: + # to docker image namespace + OWNER: '${{ github.repository_owner }}' + NAME: '${{ github.event.repository.name }}' + + - name: Get branch name + id: branch-name + uses: tj-actions/branch-names@v4.8 + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + push: true + tags: | + ${{ env.ORG_LC }}/${{ env.REPO_LC }}:${{ steps.branch-name.outputs.current_branch }} + ${{ env.ORG_LC }}/${{ env.REPO_LC }}:${{ github.sha }} + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }}