diff --git a/.github/workflows/build-test-lint.yaml b/.github/workflows/build-test-lint.yaml index 4704e5027..1a2372452 100644 --- a/.github/workflows/build-test-lint.yaml +++ b/.github/workflows/build-test-lint.yaml @@ -1,16 +1,11 @@ -name: "Ruby on Rails CI" +name: "Build & Test Docker Images" on: + push: + branches: + - develop pull_request: branches: - develop - - main - workflow_dispatch: - inputs: - debug_enabled: - type: boolean - description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' - required: false - default: false env: REGISTRY: ghcr.io @@ -20,19 +15,29 @@ jobs: runs-on: ubuntu-latest steps: - name: Set env - run: echo "TAG=${GITHUB_SHA::8}" >> $GITHUB_ENV + run: >- + echo "TAG=${HEAD_TAG::8}" >> ${GITHUB_ENV}; + echo ${HEAD_TAG::8} + env: + HEAD_TAG: ${{ github.event.pull_request.head.sha || github.sha }} + shell: bash - name: Downcase repo - run: echo "REPO_LOWER=${REPO,,}" >> $GITHUB_ENV env: - REPO: '${{ github.repository }}' + REPO: "${{ github.repository }}" + run: | + echo "REPO_LOWER=${REPO,,}" >> ${GITHUB_ENV} + shell: bash - name: Checkout code uses: actions/checkout@v3 + with: + submodules: true + token: ${{ secrets.GITHUB_TOKEN }} - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Github Container Login - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -40,70 +45,128 @@ jobs: - name: Pull from cache to speed up build run: >- touch .env.development; + touch .env; TAG=latest docker-compose pull web || true - name: Setup tmate session uses: mxschmitt/action-tmate@v3 if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} with: limit-access-to-actor: true - - name: Build and push + - name: Retag action for web + 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 + 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 + id: meta-solr + uses: docker/metadata-action@v4.1.1 + with: + images: | + name=${{ env.REGISTRY }}/${{ env.REPO_LOWER }}/solr + tags: | + type=raw,value=latest,enable={{is_default_branch}} + - name: Build and push web uses: docker/build-push-action@v3 with: + build-args: | + APP_PATH=. + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.REPO_LOWER }}:${{ env.TAG }} context: . - # platforms: linux/amd64,linux/arm64 + file: ./Dockerfile + # platforms: "linux/amd64,linux/arm64" platforms: linux/amd64 - target: ams-base - build-args: | - SETTINGS__BULKRAX__ENABLED=true - EXTRA_APK_PACKAGES=less vim bash openjdk11-jre ffmpeg rsync yarn - cache-from: | - ${{ env.REGISTRY }}/${{ env.REPO_LOWER }}:${TAG} push: true tags: | + ${{ steps.meta-web.outputs.tags }} ${{ env.REGISTRY }}/${{ env.REPO_LOWER }}:${{ env.TAG }} + target: ams-base - name: Build and push worker uses: docker/build-push-action@v3 with: + build-args: | + APP_PATH=. + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.REPO_LOWER }}/worker:${{ env.TAG }} context: . + file: ./Dockerfile platforms: linux/amd64 - # platforms: linux/amd64,linux/arm64 - target: ams-worker - build-args: | - SETTINGS__BULKRAX__ENABLED=true - EXTRA_APK_PACKAGES=less vim bash openjdk11-jre ffmpeg rsync yarn - cache-from: | - ${{ env.REGISTRY }}/${{ env.REPO_LOWER }}:${TAG} + # platforms: "linux/amd64,linux/arm64" push: true tags: | + ${{ steps.meta-worker.outputs.tags }} ${{ env.REGISTRY }}/${{ env.REPO_LOWER }}/worker:${{ env.TAG }} + target: ams-worker + - name: Build and push solr + uses: docker/build-push-action@v3 + with: + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.REPO_LOWER }}/solr:${{ env.TAG }} + context: ./solr + platforms: "linux/amd64,linux/arm64" + push: true + tags: | + ${{ steps.meta-solr.outputs.tags }} + ${{ env.REGISTRY }}/${{ env.REPO_LOWER }}/solr:${{ env.TAG }} + target: ams-solr - # lint: - # needs: build - # runs-on: ubuntu-latest - # steps: - # - name: Set env - # run: echo "TAG=${GITHUB_SHA::8}" >> $GITHUB_ENV - # # run: echo "TAG=f9867d90" >> $GITHUB_ENV - # - name: Checkout code - # uses: actions/checkout@v3 - # - name: Github Container Login - # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 - # with: - # registry: ${{ env.REGISTRY }} - # username: ${{ github.actor }} - # password: ${{ secrets.GITHUB_TOKEN }} - # - name: Pull from cache to speed up build - # run: >- - # touch .env.development; - # docker-compose pull web; - # docker-compose pull worker - # - name: Run Rubocop - # run: docker-compose run web bundle exec rubocop --parallel --format progress --format junit --out rubocop.xml --display-only-failed - # - name: Publish Test Report - # uses: mikepenz/action-junit-report@v3 - # if: always() # always run even if the previous step fails - # with: - # report_paths: 'rubocop*.xml' + lint: + needs: build + runs-on: ubuntu-latest + steps: + - name: Set env + run: >- + echo "TAG=${HEAD_TAG::8}" >> ${GITHUB_ENV}; + echo ${HEAD_TAG::8} + env: + HEAD_TAG: ${{ github.event.pull_request.head.sha || github.sha }} + shell: bash + - name: Downcase repo + env: + REPO: "${{ github.repository }}" + run: | + echo "REPO_LOWER=${REPO,,}" >> ${GITHUB_ENV} + shell: bash + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: true + token: ${{ secrets.GITHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Pull image to prevent build + run: >- + touch .env.development; + touch .env; + docker-compose pull web + - name: Pull worker image to prevent build + run: >- + docker-compose pull worker + - name: Run Rubocop + run: >- + [ -f "db/schema.rb" ] && chmod 777 db/schema.rb; + docker-compose run web bundle exec rubocop --parallel --format progress + - name: Publish Test Report + uses: mikepenz/action-junit-report@v3 + if: always() # always run even if the previous step fails + with: + report_paths: 'rubocop*.xml' test: needs: build @@ -126,39 +189,63 @@ jobs: TB_RSPEC_OPTIONS: --format RspecJunitFormatter --out rspec.xml steps: - name: Set env - run: echo "TAG=${GITHUB_SHA::8}" >> $GITHUB_ENV - # run: echo "TAG=f9867d90" >> $GITHUB_ENV + run: >- + echo "TAG=${HEAD_TAG::8}" >> ${GITHUB_ENV}; + echo ${HEAD_TAG::8} + env: + HEAD_TAG: ${{ github.event.pull_request.head.sha || github.sha }} + shell: bash + - name: Downcase repo + env: + REPO: "${{ github.repository }}" + run: | + echo "REPO_LOWER=${REPO,,}" >> ${GITHUB_ENV} + shell: bash - name: Checkout code uses: actions/checkout@v3 - - name: Github Container Login - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + submodules: true + token: ${{ secrets.GITHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull from cache to speed up build + - name: Pull image to prevent build run: >- touch .env.development; - docker-compose pull web; + touch .env; + docker-compose pull web + - name: Pull worker image to prevent build + run: >- docker-compose pull worker - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} - with: - limit-access-to-actor: true - name: Start containers - run: docker-compose up -d web - - name: Setup solr run: >- - docker-compose exec -T web bash -c - "solrcloud-upload-configset.sh /app/samvera/hyrax-webapp/solr/config && - SOLR_COLLECTION_NAME=hydra-test solrcloud-assign-configset.sh && - solrcloud-assign-configset.sh" + [ -f "db/schema.rb" ] && chmod 777 db/schema.rb; + docker-compose up -d web + - name: Check for and setup Solr if needed + shell: bash + run: | + if [ -d solr ] + then + docker-compose exec -T web sh -c \ + "solrcloud-upload-configset.sh "${CONFDIR}" && + SOLR_COLLECTION_NAME=hydra-test solrcloud-assign-configset.sh && + solrcloud-assign-configset.sh" + else + echo "No solr directory found, skipping..." + fi - name: Setup db run: >- - docker-compose exec -T web bash -c - "RAILS_ENV=test bundle exec rake db:schema:load db:migrate db:seed" + docker-compose exec -T web sh -c + "RAILS_ENV=test bundle exec rake db:create db:schema:load db:migrate" - name: Run Specs + id: run-specs env: # Specifies how many jobs you would like to run in parallel, # used for partitioning @@ -167,9 +254,10 @@ jobs: CI_NODE_INDEX: ${{ matrix.ci_node_index }} continue-on-error: true run: >- - docker-compose exec -T web bash -c - "gem install semaphore_test_boosters && - rspec_booster --job $CI_NODE_INDEX/$CI_NODE_TOTAL" + docker-compose exec -T web sh -c + "gem install semaphore_test_boosters && rspec_booster --job $CI_NODE_INDEX/$CI_NODE_TOTAL" + - name: Fail job if spec failure + run: if [[ ${{ steps.run-specs.outcome }} == "failure" ]]; then exit 1; else exit 0; fi - name: Publish Test Report uses: mikepenz/action-junit-report@v3 if: always() # always run even if the previous step fails diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml deleted file mode 100644 index baa53a349..000000000 --- a/.github/workflows/deploy.yaml +++ /dev/null @@ -1,27 +0,0 @@ -name: "Deploy" -on: - workflow_dispatch: - inputs: - environment: - description: 'Deploy to Environment' - require: true - default: 'staging' - type: choice - options: - - staging - - demo - - prod - - alpha - - bravo - - charlie - - delta - debug_enabled: - type: boolean - description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' - required: false - default: false - -jobs: - call-workflow: - uses: scientist-softserv/deploy-action/.github/workflows/deploy.yaml@main - secrets: inherit diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml deleted file mode 100644 index e9e33bea4..000000000 --- a/.github/workflows/main.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: "Retag on merge" -on: - push: - branches: - - develop - - main -env: - REGISTRY: ghcr.io - -jobs: - retag: - runs-on: ubuntu-latest - steps: - - name: Set env - run: echo "TAG=${GITHUB_SHA::8}" >> $GITHUB_ENV - - name: Downcase repo - run: | - echo "REPO_LOWER=${REPO,,}" >>${GITHUB_ENV} - env: - REPO: '${{ github.repository }}' - - name: Retag web to latest - uses: koraykoska/retag-docker-image@0.2.4 - with: - name: ${{ env.REPO_LOWER }} - old_tag: ${{ env.TAG }} - new_tag: latest - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Retag worker to latest - uses: koraykoska/retag-docker-image@0.2.4 - with: - name: ${{ env.REPO_LOWER }}/worker - old_tag: ${{ env.TAG }} - new_tag: latest - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} diff --git a/docker-compose.yml b/docker-compose.yml index df688968c..e83643924 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -75,8 +75,8 @@ services: solr: image: ams/solr:8 build: - context: solr - dockerfile: Dockerfile + context: ./solr + target: ams-solr env_file: - .env environment: diff --git a/solr/Dockerfile b/solr/Dockerfile index e89995951..bd49fe415 100644 --- a/solr/Dockerfile +++ b/solr/Dockerfile @@ -1,4 +1,4 @@ -FROM solr:8.3 +FROM solr:8.3 as ams-solr ENV SOLR_USER="solr" \ SOLR_GROUP="solr" USER root