diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 92b82db..38fa78a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -2,66 +2,46 @@ name: "Build Docker Images" on: workflow_dispatch: inputs: - baseTarget: - description: "Used to set your target for the base image" + components: + default: '["base", "solr", "web", "worker"]' + description: "Used to set your target for the components" required: false type: string image_name: description: "Docker image name part. Fills in ghcr.io/IMAGE_NAME. Typically this is the `repo_name`, but in some projects it might be `repo_name/sub_name`" type: string - platforms: - default: "linux/amd64,linux/arm64" - description: "Which platforms you would like built through CI" - type: string - solrTarget: - description: "Used to set your target for the solr image" + os: + default: '["ubuntu-latest", "ubuntu-24.04-arm"]' + description: "Used to set your target for the operating system" required: false type: string subdir: - default: '.' + default: "." type: string tag: required: false type: string - webTarget: - description: "Used to set your target for the web image" - required: false - type: string - workerTarget: - description: "Used to set your target for the worker image" - required: false - type: string workflow_call: inputs: - baseTarget: - description: "Used to set your target for the base image" + components: + default: '["base", "solr", "web", "worker"]' + description: "Used to set your target for the components" required: false type: string image_name: description: "Docker image name part. Fills in ghcr.io/IMAGE_NAME. Typically this is the `repo_name`, but in some projects it might be `repo_name/sub_name`" type: string - platforms: - default: "linux/amd64,linux/arm64" - description: "Which platforms you would like built through CI" - type: string - solrTarget: - description: "Used to set your target for the solr image" + os: + default: '["ubuntu-latest", "ubuntu-24.04-arm"]' + description: "Used to set your target for the operating system" required: false type: string subdir: - default: '.' + default: "." type: string tag: required: false type: string - webTarget: - description: "Used to set your target for the web image" - required: false - type: string - workerTarget: - description: "Used to set your target for the worker image" - required: false - type: string env: REGISTRY: ghcr.io @@ -70,22 +50,34 @@ env: jobs: build: - runs-on: ubuntu-latest + strategy: + matrix: + component: ${{fromJson(inputs.components)}} + os: ${{fromJson(inputs.os)}} + runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash steps: + - name: Set platform from matrix + run: | + if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then + echo "PLATFORM_TAG=amd64" >> $GITHUB_ENV + else + echo "PLATFORM_TAG=arm64" >> $GITHUB_ENV + fi - id: setup name: Setup - uses: notch8/actions/setup-env@v1.0.4 + uses: notch8/actions/setup-env@enter_the_matrix with: tag: ${{ inputs.tag }} image_name: ${{ inputs.image_name }} token: ${{ secrets.CHECKOUT_TOKEN || secrets.GITHUB_TOKEN }} subdir: ${{ inputs.subdir }} - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -95,79 +87,42 @@ jobs: if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_step == 'build' }} with: limit-access-to-actor: true - - name: Retag action for base - if: ${{ inputs.baseTarget != '' }} - id: meta-base - uses: docker/metadata-action@v4.1.1 - with: - images: | - name=${{ env.REGISTRY }}/${{ env.REPO_LOWER }}/base - tags: | - type=raw,value=latest,enable={{is_default_branch}} - - name: Retag action for web - if: ${{ inputs.webTarget != '' }} - id: meta-web - uses: docker/metadata-action@v4.1.1 - with: - images: | - name=${{ env.REGISTRY }}/${{ env.REPO_LOWER }} - tags: | - type=raw,value=latest,enable={{is_default_branch}} - - name: Retag action for worker - if: ${{ inputs.workerTarget != '' }} - id: meta-worker - uses: docker/metadata-action@v4.1.1 - with: - images: | - name=${{ env.REGISTRY }}/${{ env.REPO_LOWER }}/worker - tags: | - type=raw,value=latest,enable={{is_default_branch}} - - name: Retag action for solr - if: ${{ inputs.solrTarget != '' }} - id: meta-solr - uses: docker/metadata-action@v4.1.1 + - name: Build Prep + run: | + echo "Preparing build environment..." + cd ${{ inputs.subdir }}; + [ -f "db/schema.rb" ] && chmod 777 db/schema.rb; + [ -f "bin/checkout_all.sh" ] && ./bin/checkout_all.sh; + - name: Build and push ${{ matrix.component }} on ${{ matrix.os }} + uses: docker/build-push-action@v3 with: - images: | - name=${{ env.REGISTRY }}/${{ env.REPO_LOWER }}/solr + context: ${{ inputs.subdir }} + platforms: linux/${{ env.PLATFORM_TAG }} + target: ${{ matrix.component }} + cache-from: | + type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}/${{ matrix.component }}:latest + cache-to: type=inline + push: true tags: | - type=raw,value=latest,enable={{is_default_branch}} - - name: Build and push base - if: ${{ inputs.baseTarget != '' }} - uses: notch8/actions/build-and-push@v1.0.4 - with: - type: base - location: /base - subdir: ${{ inputs.subdir }} - tags: ${{ steps.meta-base.outputs.tags }} - - name: Build and push web and worker - if: ${{ inputs.webTarget != '' && inputs.workerTarget != '' }} - uses: notch8/actions/build-and-push@v1.0.4 - with: - type: web,worker - location: "" - subdir: ${{ inputs.subdir }} - tags: ${{ steps.meta-base.outputs.tags }} - - name: Build and push web - if: ${{ inputs.webTarget != '' && inputs.workerTarget == '' }} - uses: notch8/actions/build-and-push@v1.0.4 - with: - type: web - location: "" - subdir: ${{ inputs.subdir }} - tags: ${{ steps.meta-base.outputs.tags }} - - name: Build and push worker - if: ${{ inputs.workerTarget != '' && inputs.webTarget == '' }} - uses: notch8/actions/build-and-push@v1.0.4 - with: - type: worker - location: /worker - subdir: ${{ inputs.subdir }} - tags: ${{ steps.meta-worker.outputs.tags }} - - name: Build and push solr - if: ${{ inputs.solrTarget != '' }} - uses: notch8/actions/build-and-push@v1.0.4 + ${{ env.REGISTRY }}/${{ github.repository }}/${{ matrix.component }}:${{ env.TAG }}-${{ env.PLATFORM_TAG }} + + push: + needs: build + runs-on: ubuntu-latest + steps: + - id: setup + name: Setup + uses: notch8/actions/setup-env@enter_the_matrix with: - type: solr - location: /solr + tag: ${{ inputs.tag }} + image_name: ${{ inputs.image_name }} + token: ${{ secrets.CHECKOUT_TOKEN || secrets.GITHUB_TOKEN }} subdir: ${{ inputs.subdir }} - tags: ${{ steps.meta-solr.outputs.tags }} \ No newline at end of file + - name: Create multiarch manifests + run: | + components_list=$(echo '${{ inputs.components }}' | jq -r '.[]' | tr '\n' ' ') + for component in $components_list; do + docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/$component:${{ env.TAG }} \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/$component:${{ env.TAG }}-amd64 \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/$component:${{ env.TAG }}-arm64 + done diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 11473e7..547b712 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -10,7 +10,7 @@ on: required: false type: string subdir: - default: '.' + default: "." type: string tag: required: false @@ -36,7 +36,7 @@ on: required: false type: string subdir: - default: '.' + default: "." type: string tag: required: false @@ -70,7 +70,7 @@ jobs: steps: - id: setup name: Setup - uses: notch8/actions/setup-env@v1.0.4 + uses: notch8/actions/setup-env@enter_the_matrix with: tag: ${{ inputs.tag }} token: ${{ secrets.CHECKOUT_TOKEN || secrets.GITHUB_TOKEN }} @@ -131,4 +131,4 @@ jobs: uses: mikepenz/action-junit-report@v3 if: always() # always run even if the previous step fails with: - report_paths: 'cypress/results/results-*.xml' + report_paths: "cypress/results/results-*.xml" diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index a6c7663..cc6a6ae 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -2,60 +2,28 @@ name: "Lint for Rails Projects" on: workflow_dispatch: inputs: - baseTarget: - description: "Used to set your target for the base image" - required: false - type: string rubocop_cmd: default: bundle exec rubocop --parallel --format progress required: false type: string - solrTarget: - description: "Used to set your target for the solr image" - required: false - type: string subdir: default: "." type: string tag: required: false type: string - webTarget: - description: "Used to set your target for the web image" - required: false - type: string - workerTarget: - description: "Used to set your target for the worker image" - required: false - type: string workflow_call: inputs: - baseTarget: - description: "Used to set your target for the base image" - required: false - type: string rubocop_cmd: default: bundle exec rubocop --parallel --format progress --format junit --out rubocop.xml --display-only-failed required: false type: string - solrTarget: - description: "Used to set your target for the solr image" - required: false - type: string subdir: default: "." type: string tag: required: false type: string - webTarget: - description: "Used to set your target for the web image" - required: false - type: string - workerTarget: - description: "Used to set your target for the worker image" - required: false - type: string env: REGISTRY: ghcr.io @@ -68,7 +36,7 @@ jobs: steps: - id: setup name: Setup - uses: notch8/actions/setup-env@v1.0.4 + uses: notch8/actions/setup-env@enter_the_matrix with: tag: ${{ inputs.tag }} token: ${{ secrets.CHECKOUT_TOKEN || secrets.GITHUB_TOKEN }} @@ -94,7 +62,7 @@ jobs: "${{ inputs.rubocop_cmd }}" - id: after_care name: Upload Logs and Results - uses: notch8/actions/after-care@v1.0.4 + uses: notch8/actions/after-care@enter_the_matrix if: always() with: reports: "rubocop*.xml" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 54a42f5..e9589e7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,10 +2,6 @@ name: "Rspec for Rails Apps" on: workflow_dispatch: inputs: - baseTarget: - description: "Used to set your target for the base image" - required: false - type: string confdir: description: "Solr conf/config directory" required: false @@ -50,10 +46,6 @@ on: type: string workflow_call: inputs: - baseTarget: - description: "Used to set your target for the base image" - required: false - type: string confdir: required: false type: string @@ -113,7 +105,7 @@ jobs: steps: - id: setup name: Setup - uses: notch8/actions/setup-env@v1.0.4 + uses: notch8/actions/setup-env@enter_the_matrix with: tag: ${{ inputs.tag }} token: ${{ secrets.CHECKOUT_TOKEN || secrets.GITHUB_TOKEN }} @@ -175,7 +167,7 @@ jobs: fi - id: after_care name: Upload Logs and Results - uses: notch8/actions/after-care@v1.0.4 + uses: notch8/actions/after-care@enter_the_matrix if: always() with: reports: "rspec-*.xml" diff --git a/.github/workflows/update-deploy-values.yaml b/.github/workflows/update-deploy-values.yaml index 004f3e8..324a1d8 100644 --- a/.github/workflows/update-deploy-values.yaml +++ b/.github/workflows/update-deploy-values.yaml @@ -15,7 +15,7 @@ jobs: steps: - id: setup name: Setup - uses: notch8/actions/setup-env@v1.0.4 + uses: notch8/actions/setup-env@enter_the_matrix with: token: ${{ secrets.CHECKOUT_TOKEN || secrets.GITHUB_TOKEN }} diff --git a/build-and-push/action.yaml b/build-and-push/action.yaml deleted file mode 100644 index e2c6383..0000000 --- a/build-and-push/action.yaml +++ /dev/null @@ -1,61 +0,0 @@ -name: "build and push images" -description: "build and push images do docker using docker compose" -inputs: - location: - required: false - type: string - subdir: - required: false - type: string - tags: - required: false - type: string - type: - required: false - type: string - -runs: - using: "composite" - steps: - - name: Determine BASE_TAG (submodule-aware) - id: base_tag - shell: bash - run: | - if [ -e "${{ inputs.subdir }}/hyrax-webapp/.git" ]; then - echo "Submodule detected" - BASE_TAG=$(cd ${{ inputs.subdir }}/hyrax-webapp && git rev-parse --short=8 HEAD) - else - echo "No submodule found, using 'latest'" - BASE_TAG="latest" - fi - - echo "BASE_TAG=$BASE_TAG" >> $GITHUB_ENV - echo "BASE_TAG set to $BASE_TAG" - - - name: Build and push ${{ inputs.type }} - env: - BUILD_LOCATION: ${{ inputs.location }} - BUILD_TYPE: ${{ inputs.type }} - TAGS: ${{ inputs.tags }} - shell: bash - run: >- - cd ${{ inputs.subdir }}; - [ -f "db/schema.rb" ] && chmod 777 db/schema.rb; - [ -f "bin/checkout_all.sh" ] && ./bin/checkout_all.sh; - docker compose pull base || true; - if [ ${BUILD_TYPE} = "web,worker" ]; then - BUILD_LOCATION=''; - TAG=latest docker compose pull web || true; - docker compose build web --build-arg BUILDKIT_INLINE_CACHE=1 && - docker compose push web && - ruby -e "ENV.fetch('TAGS', []).split(',').each {|tag| %x{docker tag #{ENV['REGISTRY']}/#{ENV['REPO_LOWER']}#{ENV['BUILD_LOCATION']}:#{ENV['TAG']} #{ENV['REGISTRY']}/#{ENV['REPO_LOWER']}#{ENV['BUILD_LOCATION']}:#{tag}}; %x{docker push #{ENV['REGISTRY']}/#{ENV['REPO_LOWER']}#{ENV['BUILD_LOCATION']}:#{tag}}}" && - BUILD_LOCATION='/worker' && - docker compose build worker --build-arg BUILDKIT_INLINE_CACHE=1 && - docker compose push worker && - ruby -e "ENV.fetch('TAGS', []).split(',').each {|tag| %x{docker tag #{ENV['REGISTRY']}/#{ENV['REPO_LOWER']}#{ENV['BUILD_LOCATION']}:#{ENV['TAG']} #{ENV['REGISTRY']}/#{ENV['REPO_LOWER']}#{ENV['BUILD_LOCATION']}:#{tag}}; %x{docker push #{ENV['REGISTRY']}/#{ENV['REPO_LOWER']}#{ENV['BUILD_LOCATION']}:#{tag}}}"; - else - TAG=latest docker compose pull ${BUILD_TYPE} || true; - docker compose build ${BUILD_TYPE} --build-arg BUILDKIT_INLINE_CACHE=1 && - docker compose push ${BUILD_TYPE} && - ruby -e "ENV.fetch('TAGS', []).split(',').each {|tag| %x{docker tag #{ENV['REGISTRY']}/#{ENV['REPO_LOWER']}#{ENV['BUILD_LOCATION']}:#{ENV['TAG']} #{ENV['REGISTRY']}/#{ENV['REPO_LOWER']}#{ENV['BUILD_LOCATION']}:#{tag}}; %x{docker push #{ENV['REGISTRY']}/#{ENV['REPO_LOWER']}#{ENV['BUILD_LOCATION']}:#{tag}}}"; - fi diff --git a/setup-env/action.yaml b/setup-env/action.yaml index f93c7b9..5281f52 100644 --- a/setup-env/action.yaml +++ b/setup-env/action.yaml @@ -5,7 +5,7 @@ inputs: required: false type: string subdir: - default: '.' + default: "." type: string tag: required: false @@ -17,12 +17,17 @@ inputs: runs: using: "composite" steps: + - name: Determine git sha to checkout + uses: haya14busa/action-cond@v1 + id: gitsha + with: + cond: ${{ github.event_name == 'pull_request' }} + if_true: ${{ github.event.pull_request.head.sha }} + if_false: ${{ github.sha }} - name: Set env - run: >- - echo "TAG=${HEAD_TAG::8}" >> ${GITHUB_ENV}; - echo ${HEAD_TAG::8} + run: echo "TAG=${GIT_SHA::8}" >> $GITHUB_ENV env: - HEAD_TAG: ${{ inputs.tag || github.event.pull_request.head.sha || github.sha }} + GIT_SHA: ${{ steps.gitsha.outputs.value }} shell: bash - name: Downcase repo env: