Add CI pipeline to build image #9
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 Image | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Install jq | |
run: sudo apt-get update && sudo apt-get install -y jq | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USER_RW }} | |
password: ${{ secrets.DOCKER_PAT_RW }} | |
- name: Check modified files | |
id: files | |
run: | | |
git diff --name-only HEAD~1 HEAD | |
git diff --name-only HEAD~1 HEAD | grep 'linea-besu/build-.*\.json' | |
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD | grep 'linea-besu/build-.*\.json' | xargs) | |
echo "Detected changed files: $CHANGED_FILES" | |
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV | |
- name: Download and Prepare Artifacts | |
run: | | |
if [[ -z "${{ env.CHANGED_FILES }}" ]]; then | |
echo "No changed files detected." | |
exit 0 | |
fi | |
CONFIG_FILE="linea-besu/build-${{ matrix.environment }}.json" | |
if echo "${{ env.CHANGED_FILES }}" | grep -q "linea-besu/build-${{ matrix.environment }}.json"; then | |
mkdir -p besu/${{ matrix.environment }}/plugins besu/${{ matrix.environment }}/profiles besu/${{ matrix.environment }}/config besu/${{ matrix.environment }}/genesis | |
jq -c '.modules[]' "$CONFIG_FILE" | while read -r module; do | |
type=$(echo "$module" | jq -r '.type') | |
name=$(echo "$module" | jq -r '.name') | |
url=$(echo "$module" | jq -r '.url') | |
version=$(echo "$module" | jq -r '.version') | |
outputDir=$(echo "$module" | jq -r '.outputDir // empty') | |
case "$type" in | |
"extract") | |
curl -L "${url/\{version\}/$version}" | tar xz -C "besu/${{ matrix.environment }}/${outputDir}" | |
;; | |
"download") | |
curl -L "${url/\{version\}/$version}" -o "besu/${{ matrix.environment }}/${outputDir}/$name-$version.jar" | |
;; | |
"copy") | |
cp -r "$name" "besu/${{ matrix.environment }}/${outputDir}" | |
;; | |
esac | |
done | |
else | |
echo "$CONFIG_FILE not modified." | |
fi | |
shell: /usr/bin/bash -e {0} | |
- name: Define Artifact Versions | |
id: artifact-versions | |
run: | | |
CONFIG_FILE="linea-besu/build-${{ matrix.environment }}.json" | |
if echo "${{ env.CHANGED_FILES }}" | grep -q "linea-besu/build-${{ matrix.environment }}.json"; then | |
linea_besu_version=$(jq -r '.modules[] | select(.name=="linea-besu") | .version' "$CONFIG_FILE") | |
linea_sequencer_version=$(jq -r '.modules[] | select(.name=="linea-sequencer") | .version' "$CONFIG_FILE") | |
finalized_tag_updater_version=$(jq -r '.modules[] | select(.name=="finalized-tag-updater") | .version' "$CONFIG_FILE") | |
echo "::set-output name=linea_besu_version::$linea_besu_version" | |
echo "::set-output name=linea_sequencer_version::$linea_sequencer_version" | |
echo "::set-output name=finalized_tag_updater_version::$finalized_tag_updater_version" | |
- name: Build and push Docker image | |
if: contains(env.CHANGED_FILES, 'linea-besu/build-${{ matrix.environment }}.json') | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: | | |
linea-besu-package:${{ matrix.environment }}-${{ steps.artifact-versions.outputs.linea_besu_version }}-${{ steps.artifact-versions.outputs.linea_sequencer_version }}-${{ steps.artifact-versions.outputs.finalized_tag_updater_version }} | |