testing the "include_path_file" variable #1
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 Slim Image and Push to Registries | ||
on: | ||
workflow_call: | ||
inputs: | ||
DOCKERFILE_LOCATION: | ||
required: false | ||
type: string | ||
default: "./Dockerfile" | ||
AWS_REGION: | ||
required: false | ||
type: string | ||
default: "us-east-1" | ||
AWS_ECR_REGISTRY: | ||
required: false | ||
type: string | ||
default: "707767160287.dkr.ecr.us-east-1.amazonaws.com" | ||
DOCKERFILE_BUILD_CONTEXT: | ||
required: false | ||
type: string | ||
default: "." | ||
OVERRIDE_REPO_NAME: | ||
required: false | ||
type: string | ||
default: "" | ||
OVERRIDE_TAG_NAME: | ||
required: false | ||
type: string | ||
default: "" | ||
USE_QUAY_ONLY: | ||
required: false | ||
type: boolean | ||
default: false | ||
BUILD_PLATFORMS: | ||
required: false | ||
type: string | ||
default: "linux/amd64, linux/arm64" | ||
secrets: | ||
ECR_AWS_ACCESS_KEY_ID: | ||
required: true | ||
ECR_AWS_SECRET_ACCESS_KEY: | ||
required: true | ||
QUAY_USERNAME: | ||
required: true | ||
QUAY_ROBOT_TOKEN: | ||
required: true | ||
jobs: | ||
ci: | ||
name: Build Image and Push | ||
runs-on: ubuntu-latest | ||
steps: | ||
# https://github.com/docker/login-action#quayio | ||
- name: Login to Quay.io | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: quay.io | ||
username: ${{ secrets.QUAY_USERNAME }} | ||
password: ${{ secrets.QUAY_ROBOT_TOKEN }} | ||
# https://github.com/docker/login-action#aws-public-elastic-container-registry-ecr | ||
- name: Login to ECR | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ inputs.AWS_ECR_REGISTRY }} | ||
username: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }} | ||
password: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }} | ||
env: | ||
AWS_REGION: ${{ inputs.AWS_REGION }} | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
persist-credentials: false | ||
fetch-depth: 0 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
- name: Set Variables | ||
shell: bash | ||
run: | | ||
echo "OVERRIDE_REPO_NAME = ${{ inputs.OVERRIDE_REPO_NAME }}" | ||
echo "OVERRIDE_TAG_NAME = ${{ inputs.OVERRIDE_TAG_NAME }}" | ||
if [[ -z "${{ inputs.OVERRIDE_TAG_NAME }}" ]] | ||
then | ||
echo "No OVERRIDE_TAG_NAME input provided, defaulting to current branch/tag name..." | ||
echo "IMAGE_TAG=$(echo ${GITHUB_REF#refs/*/} | tr / _)" | ||
echo "IMAGE_TAG=$(echo ${GITHUB_REF#refs/*/} | tr / _)" >> $GITHUB_ENV | ||
else | ||
echo "OVERRIDE_TAG_NAME provided, using it for IMAGE_TAG..." | ||
echo "IMAGE_TAG=${{ inputs.OVERRIDE_TAG_NAME }}" | ||
echo "IMAGE_TAG=${{ inputs.OVERRIDE_TAG_NAME }}" >> $GITHUB_ENV | ||
fi | ||
if [[ -z "${{ inputs.OVERRIDE_REPO_NAME }}" ]] | ||
then | ||
echo "No OVERRIDE_REPO_NAME input provided, defaulting to repo name..." | ||
echo "REPO_NAME=$(echo $GITHUB_REPOSITORY | awk -F / '{print $2}')" | ||
echo "REPO_NAME=$(echo $GITHUB_REPOSITORY | awk -F / '{print $2}')" >> $GITHUB_ENV | ||
else | ||
echo "OVERRIDE_REPO_NAME provided, using it for REPO_NAME..." | ||
echo "REPO_NAME=${{ inputs.OVERRIDE_REPO_NAME }}" | ||
echo "REPO_NAME=${{ inputs.OVERRIDE_REPO_NAME }}" >> $GITHUB_ENV | ||
fi | ||
- name: Extract metadata | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: | | ||
quay.io/cdis/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} | ||
${{ inputs.AWS_ECR_REGISTRY }}/gen3/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} | ||
# - name: Build | ||
# if: ${{ !inputs.USE_QUAY_ONLY }} | ||
# uses: docker/build-push-action@v3 | ||
# # You may get ECR-push errors when first adding the workflow to a github repo. | ||
# # If so, run the following in dev/qa to create the ECR repository: | ||
# # qaplanetv1@cdistest_dev_admin:~$ aws ecr create-repository --repository-name "gen3/<repo name>" --image-scanning-configuration scanOnPush=true | ||
# with: | ||
# context: ${{ inputs.DOCKERFILE_BUILD_CONTEXT }} | ||
# file: ${{ inputs.DOCKERFILE_LOCATION }} | ||
# push: false | ||
# tags: | | ||
# quay.io/cdis/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} | ||
# ${{ inputs.AWS_ECR_REGISTRY }}/gen3/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} | ||
# labels: ${{ steps.meta.outputs.labels }} | ||
# cache-from: type=registry,ref=${{ inputs.AWS_ECR_REGISTRY }}/gen3/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} | ||
# cache-to: type=inline | ||
# platforms: ${{ inputs.BUILD_PLATFORMS }} | ||
# - name: Slim | ||
# if: ${{ !inputs.USE_QUAY_ONLY }} | ||
# uses: kitabisa/docker-slim-action@v1 | ||
# with: | ||
# target: ${{ github.repository }}:latest | ||
# tag: "slim" | ||
# env: | ||
# DSLIM_HTTP_PROBE: false | ||
# - name: Push | ||
# if: ${{ !inputs.USE_QUAY_ONLY }} | ||
# run: | | ||
# docker image push "${{ github.repository }}" --all-tags | ||
- name: Build and push (Quay only) | ||
# if: ${{ inputs.USE_QUAY_ONLY }} | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ${{ inputs.DOCKERFILE_BUILD_CONTEXT }} | ||
file: ${{ inputs.DOCKERFILE_LOCATION }} | ||
push: true | ||
tags: | | ||
quay.io/cdis/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: ${{ inputs.BUILD_PLATFORMS }} | ||
- name: Slim (Quay only) | ||
# if: ${{ inputs.USE_QUAY_ONLY }} | ||
uses: kitabisa/docker-slim-action@v1 | ||
with: | ||
target: quay.io/cdis/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} | ||
tag: ${{ env.IMAGE_TAG }}-slim | ||
env: | ||
DSLIM_HTTP_PROBE: true | ||
DSLIM_INCLUDE_PATH_FILE: "/usr/bin/sort:/usr/bin/find:/bin/rm:/bin/tar | ||
- name: Push (Quay only) | ||
# if: ${{ inputs.USE_QUAY_ONLY }} | ||
run: | | ||
docker image push quay.io/cdis/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }}-slim |