add container-build-and-push CI step #77
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & Install | |
on: [push] | |
permissions: | |
contents: read | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build-and-install: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
go-arch: ["amd64", "arm", "arm64"] | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-go@v3 | |
with: | |
go-version: 1.19.4 | |
- name: Build | |
run: GOARCH=${{ matrix.go-arch }} make build | |
- name: Install | |
run: make install | |
container-build-and-push: | |
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' | |
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 | |
run: docker login --username ${{ secrets.DOCKER_HUB_USERNAME }} --password ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} docker.io | |
- name: Build and Push | |
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 |