Merge pull request #369 from Mariam05/LTI-411-dbindex #295
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 Push | |
on: | |
push: | |
branches-ignore: | |
- 'dependabot**' | |
- 'snyk**' | |
- 'release**' | |
jobs: | |
main: | |
name: Build Docker Image | |
env: | |
DOCKER_REPOSITORY: ${{ secrets.DOCKER_REPOSITORY }} | |
DOCKER_BUILD_ENABLED: ${{ secrets.DOCKER_BUILD_ENABLED }} | |
DOCKER_BUILD_ALTERNATE_ENABLED: ${{ secrets.DOCKER_BUILD_ALTERNATE_ENABLED }} | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
if: contains(env.DOCKER_BUILD_ENABLED, 'true') | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
if: contains(env.DOCKER_BUILD_ENABLED, 'true') | |
uses: docker/setup-buildx-action@v3 | |
- name: Cache Docker layers | |
if: contains(env.DOCKER_BUILD_ENABLED, 'true') | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Login to DockerHub | |
if: contains(env.DOCKER_BUILD_ENABLED, 'true') | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Extract Docker Repository | |
id: ci_docker_repository | |
if: contains(env.DOCKER_BUILD_ENABLED, 'true') | |
shell: bash | |
run: echo "repository=$(echo ${DOCKER_REPOSITORY:-$GITHUB_REPOSITORY})" >> $GITHUB_OUTPUT | |
- name: Extract Branch Name | |
id: ci_branch_name | |
if: contains(env.DOCKER_BUILD_ENABLED, 'true') | |
shell: bash | |
run: echo "branch=$(echo ${{github.ref_name}})" >> $GITHUB_OUTPUT | |
- name: Extract Commit Short SHA | |
id: ci_commit_short_sha | |
if: contains(env.DOCKER_BUILD_ENABLED, 'true') | |
shell: bash | |
run: echo "short_sha=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_OUTPUT | |
- name: Build and Push branch | |
if: contains(env.DOCKER_BUILD_ENABLED, 'true') | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: | | |
"${{ steps.ci_docker_repository.outputs.repository }}:${{ steps.ci_branch_name.outputs.branch }}" | |
build-args: "BUILD_NUMBER=${{ steps.ci_branch_name.outputs.branch }} (${{ steps.ci_commit_short_sha.outputs.short_sha }})" | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
- name: Move cache | |
if: contains(env.DOCKER_BUILD_ENABLED, 'true') | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |