From 71f7ceb62f14d26e8542f85dd5a5122dd7eea4fd Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Mon, 27 May 2024 20:37:53 +0300 Subject: [PATCH] add container-build-and-push CI step Signed-off-by: onur-ozkan --- .github/workflows/build-and-install.yml | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/build-and-install.yml b/.github/workflows/build-and-install.yml index a6e6da0..b3eeef9 100644 --- a/.github/workflows/build-and-install.yml +++ b/.github/workflows/build-and-install.yml @@ -24,3 +24,30 @@ jobs: - name: Install run: make install + + container-build-and-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Calculate commit hash for PR commit + if: github.event_name == 'pull_request' + run: echo "COMMIT_HASH=$(git rev-parse --short=7 ${{ github.event.pull_request.head.sha }})" >> $GITHUB_ENV + + - name: Calculate commit hash for merge commit + if: github.event_name != 'pull_request' + run: echo "COMMIT_HASH=$(git rev-parse --short=7 HEAD)" >> $GITHUB_ENV + + - name: Login to dockerhub + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' + run: docker login --username ${{ secrets.DOCKER_HUB_USERNAME }} --password ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} docker.io + + - name: Build and Push + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' + run: | + docker build -t komodoofficial/nucleusd:"$COMMIT_HASH" -t komodoofficial/nucleusd:latest -f ./Dockerfile + # Here we push two images. "latest" image gets overridden with each + # push and $COMMIT_HASH is a constant image so we can use a specific + # build in container environments if needed (usually for debugging purposes). + docker push komodoofficial/nucleusd:"$COMMIT_HASH" + docker push komodoofficial/nucleusd:latest