Skip to content

Change NNF_CONTAINER_PORTS env var #55

Change NNF_CONTAINER_PORTS env var

Change NNF_CONTAINER_PORTS env var #55

Workflow file for this run

name: Docker build and push
on:
push:
branches:
- '*'
tags:
- 'v*'
pull_request:
branches:
- 'master'
- 'releases/v*'
- 'feature/*'
env:
# TEST_TARGET: Name of the testing target in the Dockerfile
TEST_TARGET: testing
# DO_TEST - true to build and run unit tests, false to skip the tests
DO_TEST: false
# DO_PUSH - true to push to the HPE_DEPLOY_REPO, false to not push
DO_PUSH: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Lowercase repository name for docker build
id: lowercase-repository-name
run: |
echo "HPE_BUILD_REPO=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "HPE_DEPLOY_REPO=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: set TAG & TESTTAG for main/master
if: ${{ github.event.repository.default_branch == 'main' || github.event.repository.default_branch == 'master' }}
run: |
echo "TAG=${{ github.sha }}" >> ${GITHUB_ENV}
echo "LATESTTAG=latest" >> ${GITHUB_ENV}
echo "TESTTAG=test-${{ github.sha }}" >> ${GITHUB_ENV}
- name: set TAG & TESTTAG for all other branches
if: ${{ github.event.repository.default_branch != 'main' && github.event.repository.default_branch != 'master' }}
run: |
echo "TAG=dev-${{ github.sha }}" >> ${GITHUB_ENV}
echo "LATESTTAG=dev-latest" >> ${GITHUB_ENV}
echo "TESTTAG=test-${{ github.sha }}" >> ${GITHUB_ENV}
- name: Docker login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the test Docker image
if: ${{ env.DO_TEST == 'true' }}
id: docker_build_test_target
uses: docker/build-push-action@v2
with:
push: false
target: ${{ env.TEST_TARGET }}
tags: ${{ env.HPE_BUILD_REPO }}:${{ env.TESTTAG }}
- name: Run the Docker image unit tests
if: ${{ env.DO_TEST == 'true' }}
run: docker run ${HPE_BUILD_REPO}:${TESTTAG}
- name: Build the final Docker image
id: docker_build
uses: docker/build-push-action@v2
with:
push: false
tags: ${{ env.HPE_BUILD_REPO }}:${{ env.TAG }}
- name: Peek at the docker images
run: docker images
- name: Tag the build
run: docker tag docker.io/${HPE_BUILD_REPO}:${TAG} ghcr.io/${HPE_DEPLOY_REPO}:${TAG}
- name: Tag the build as latest
run: docker tag ${HPE_BUILD_REPO}:${TAG} ghcr.io/${HPE_DEPLOY_REPO}:${LATESTTAG}
- name: Push the tagged build
if: ${{ env.DO_PUSH == 'true' }}
run: docker push ghcr.io/${HPE_DEPLOY_REPO}:${TAG}
- name: Push the build tagged as latest
if: ${{ env.DO_PUSH == 'true' }}
run: docker push ghcr.io/${HPE_DEPLOY_REPO}:${LATESTTAG}