Skip to content

test new build

test new build #79

name: All in One Test
on:
push:
branches:
- feature/docker-image
# define the workflow that will trigger this workflow to run
# workflow_run:
# workflows: [sharing data in a workflow]
# types:
# - completed
# allow the workflow to run manually with version as input
# workflow_dispatch:
# inputs:
# build_version:
# description: 'Crawler Version Number'
# required: false
# type: string
# manually set the version number of testing purpose
env:
manual_build_version: "" # manual set value of the build version
committer_types: "es solr db" # different types of committers
jobs:
# job to build the base crawler image
build-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: feature/docker-image
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# check which value should be used as the version value
- name: Use conditional value
run: |
if [[ $manual_build_version == '' ]]; then
echo "tmp_version=$(cat pom.xml | grep -m1 "version" | sed 's/<.*>\(.*\)<.*>/\1/' | sed 's/^[ ]*//g')" >> $GITHUB_ENV
else
echo "tmp_version=$manual_build_version" >> $GITHUB_ENV
fi
# print the value of the env version variable for debugging use
- name: print the value of GITHUB_ENV:version
run: |
#echo "read-data-version:$(cat pom.xml | grep -m1 "version" | sed 's/<.*>\(.*\)<.*>/\1/' | sed 's/^[ ]*//g')"
#echo "input-version: ${{ inputs.build_version }}"
echo "manual_build_version: $manual_build_version"
echo "GITHUB_ENV_TMP_Version: ${{ env.tmp_version }}"
# convert the string to lower case for SNAPSHOT build
- name: convert string to lowercase
id: string
uses: ASzc/change-string-case-action@v1
with:
string: ${{ env.tmp_version }}
# assign the lowercase value back to an variable for later use
- run: |
echo "version=${{ steps.string.outputs.lowercase }}" >> $GITHUB_ENV
#echo "version=${{ steps.string.outputs.lowercase }}" >> $GITHUB_ENV
echo "lowercase: ${{ steps.string.outputs.lowercase }}"
# debug use only
- run: |
echo "GITHUB_ENV_Version: ${{ env.version }}"
# build the crawler base docker image
- name: Build docker base image
run: |
pwd
ls -a
docker build . --file .github/workflows/docker-files/Dockerfile-base --tag ${{env.version}}-crawler-base
# update the FROM statement in Dockerfile with the right version number
- name: Update Dockerfile with version to build
run: sed -i 's/replace-this-with-real-version/${{env.version}}/g' .github/workflows/docker-files/Dockerfile-com
# extract version number from value and assign it to different variables for tagging use
- name: Extract version numbers
run: |
if [[ "${{env.version}}" == *"-snapshot"* ]]; then
echo "snapshot_image=${{env.version}}" >> $GITHUB_ENV
else
# Extract major version
echo "major=$(echo ${{env.version}} | cut -d '.' -f 1)" >> $GITHUB_ENV
# Extract major_minor version
echo "major_minor=$(echo ${{env.version}} | cut -d '.' -f 1-2)" >> $GITHUB_ENV
fi
# debug use only
- name: print extracted version numbers
run: |
# Print extracted version numbers
echo "Major: ${{ env.major }}"
echo "Major_Minor: ${{ env.major_minor }}"
echo "Snapshot_Image: ${{ env.snapshot_image }}"
### For additional committers, add the committer type to the variable "committer_types" in the env variable section
- name: Build committer images
run: |
for type in $committer_types; do
cp .github/workflows/docker-files/Dockerfile-com .github/workflows/docker-files/Dockerfile-com-$type
#sed -i 's/replace-this-with-committer-files-in-dockerfile/$type-folder/g' .github/workflows/docker-files/Dockerfile-com-$type
more .github/workflows/docker-files/Dockerfile-com-$type
docker build . --file .github/workflows/docker-files/Dockerfile-com-$type --build-arg build_version=${{env.version}} --build-arg committer_type=$type --tag ${{env.version}}-crawler-$type
docker image ls -a
done
# login to Dockerhub
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
# Tag and push images onto Dockerhub repo
- name: Tag and Push images to Dockerhub
run: |
# check if it is a snapshot build, if not, upload different favor of images
if [[ "${{env.version}}" != *"-snapshot"* ]]; then
docker image tag ${{env.version}}-crawler-base norconex/crawler:latest
docker image tag ${{env.version}}-crawler-base norconex/crawler:${{env.major}}
docker image tag ${{env.version}}-crawler-base norconex/crawler:${{env.major_minor}}
docker image tag ${{env.version}}-crawler-base norconex/crawler:${{env.version}}
for type in $committer_types; do
docker image tag ${{env.version}}-crawler-es norconex/crawler:${{env.major}}-$type
docker image tag ${{env.version}}-crawler-es norconex/crawler:${{env.major_minor}}-$type
docker image tag ${{env.version}}-crawler-es norconex/crawler:${{env.version}}-$type
done
# check what images are created
#docker image ls -a
# upload to dockerhub
docker push norconex/crawler:latest
docker push norconex/crawler:${{env.major}}
docker push norconex/crawler:${{env.major_minor}}
docker push norconex/crawler:${{env.version}}
for type in $committer_types; do
docker push norconex/crawler:${{env.major}}-$type
docker push norconex/crawler:${{env.major_minor}}-$type
docker push norconex/crawler:${{env.version}}-$type
done
echo "Base, and committers images uploaded!"
else
# tag the local images with repo inform for upload use
docker image tag ${{env.version}}-crawler-base norconex/crawler:${{env.version}}
# tag images for different committer type
for type in $committer_types; do
docker image tag ${{env.version}}-crawler-$type norconex/crawler:${{env.version}}-$type
done
# upload tagged images to dockerhub
docker push norconex/crawler:${{env.version}}
# upload different type of committer images
for type in $committer_types; do
docker push norconex/crawler:${{env.version}}-$type
done
echo "snapshot uploaded!"
fi