Skip to content

if updating latest, create X.Y tag instead of X.Y-latest #369

if updating latest, create X.Y tag instead of X.Y-latest

if updating latest, create X.Y tag instead of X.Y-latest #369

name: Create Development Docker Images
on:
push:
branches:
- develop
- 'main_v**'
- 'feature_**'
- 'bugfix_**'
pull_request:
types: [opened, reopened, synchronize]
branches:
- develop
- 'main_v**'
workflow_dispatch:
inputs:
github_name:
description: 'Branch to build, e.g. develop'
default: 'develop'
required: true
type: string
push_image:
description: 'Push images to Docker Hub'
default: false
type: boolean
env:
DOCKERHUB_BASE_REPO: dtcenter/met-base-dev
DOCKERHUB_UNIT_TEST_REPO: dtcenter/met-base-unit-test-dev
DOCKERHUB_METVIEWER_REPO: dtcenter/met-base-metviewer-dev
DEBIAN_REGISTRY: registry1.dso.mil
DEBIAN_IMAGE: ironbank/opensource/debian/debian
jobs:
job_control:
name: Set run options
runs-on: ubuntu-latest
steps:
- name: Set run options
id: job_status
run: |
if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then
github_name=${{ inputs.github_name }}
push_image=${{ inputs.push_image }}
elif [[ ${{ github.event_name }} == 'pull_request' ]]; then
github_name=${{ github.sha }}
push_image='true'
else
github_name=${{ github.ref_name }}
push_image='true'
fi
echo "github_name=${github_name}" >> $GITHUB_OUTPUT
echo "push_image=${push_image}" >> $GITHUB_OUTPUT
outputs:
github_name: ${{ steps.job_status.outputs.github_name }}
push_image: ${{ steps.job_status.outputs.push_image }}
build_scan_and_push:
name: Build, Scan, and Push Images
runs-on: ubuntu-latest
needs: job_control
strategy:
fail-fast: false
matrix:
component: [met, metviewer]
steps:
- uses: actions/checkout@v6
- name: Free Disk Space
uses: dtcenter/metplus-action-free-disk-space@v1
- uses: actions/checkout@v6
with:
ref: ${{ needs.job_control.outputs.github_name }}
path: ${{ needs.job_control.outputs.github_name }}
- name: Create directories to store build log output
run: mkdir -p ${RUNNER_WORKSPACE}/logs
- name: Authenticate IronBank
run: echo "${{ secrets.IRONBANK_SECRET }}" | docker login -u ${{ secrets.IRONBANK_USERNAME }} --password-stdin registry1.dso.mil
- name: Build Docker Image
run: .github/jobs/build_docker_image.sh
env:
GITHUB_NAME: ${{ needs.job_control.outputs.github_name }}
METPLUS_COMPONENT: ${{ matrix.component }}
- name: Copy build log files into logs directory
if: always()
run: cp ${GITHUB_WORKSPACE}/*.log ${RUNNER_WORKSPACE}/logs/
- name: Upload build logs as artifact
if: always()
uses: actions/upload-artifact@v7
with:
name: build_logs_${{ matrix.component }}
path: ${{ runner.workspace }}/logs
if-no-files-found: ignore
# scan DOCKERHUB_BASE_REPO and DOCKERHUB_UNIT_TEST_REPO if component is met
# scan DOCKERHUB_METVIEWER_REPO if component is metviewer
- name: Scan Docker Images
id: scan
continue-on-error: true
uses: dtcenter/metplus-action-scan-docker-images@v2
with:
images: |
[
${{ matrix.component == 'met' && format('"{0}:{2}", "{1}:{2}"', env.DOCKERHUB_BASE_REPO, env.DOCKERHUB_UNIT_TEST_REPO, needs.job_control.outputs.github_name) || format('"{0}:{1}"', env.DOCKERHUB_METVIEWER_REPO, needs.job_control.outputs.github_name) }}
]
fail-on-critical: "false"
log-artifact-name: "security-scan-logs_${{ matrix.component }}"
- name: Push Docker Image
if: ${{ needs.job_control.outputs.push_image == 'true' }}
run: .github/jobs/push_docker_image.sh
env:
GITHUB_NAME: ${{ needs.job_control.outputs.github_name }}
METPLUS_COMPONENT: ${{ matrix.component }}
DOCKER_USERNAME: 'dtcenter'
DOCKER_PASSWORD: ${{ secrets.DOCKER_TOKEN }}