diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index b24a031a4..d190848b7 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,11 +2,6 @@ name: Docker Image CI/CD on: push: - branches: - - master - pull_request: - branches: - - master jobs: push_to_registry: @@ -14,52 +9,43 @@ jobs: if: github.event_name == 'push' runs-on: ubuntu-latest steps: - - name: Check Repository + - name: Checkout Repository uses: actions/checkout@v4 - - name: Cache SBT Dependencies - uses: actions/cache@v4 - with: - path: | - ~/.ivy2 - ~/.sbt - key: ${{ runner.os }}-sbt-${{ hashFiles('**/Build.sbt') }} - restore-keys: | - ${{ runner.os }}-sbt- - - name: Login to Docker Registry uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_HUB_EMAIL }} password: ${{ secrets.DOCKER_HUB_PASSWORD }} - - name: Build and Push Docker Image to Registry - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: teamfemrdev/teamfemr:latest - - build: - name: Build Docker Image on Pull Request - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Check Repository - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Cache SBT Dependencies - uses: actions/cache@v4 + - name: Cache Docker Dependencies + uses: actions/cache@v3 with: path: | - ~/.ivy2 - ~/.sbt - key: ${{ runner.os }}-sbt-${{ hashFiles('**/Build.sbt') }} + root/.ivy2 + root/.sbt + key: sbt-${{ runner.os }}-${{ hashFiles('**/build.sbt', '**/project/*.sbt') }} restore-keys: | - ${{ runner.os }}-sbt- + sbt-${{ runner.os }}- - - name: Build Docker Image - uses: docker/build-push-action@v5 + - name: Inject sbt cache into Docker + uses: reproducible-containers/buildkit-cache-dance@v3.1.0 + with: + cache-map: | + { + "root/.ivy2": "/root/.ivy2", + "root/.sbt": "/root/.sbt" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} + + - name: Build and Push Docker Image to Registry + uses: docker/build-push-action@v6 with: context: . - push: false + cache-from: type=gha + cache-to: type=gha,mode=max + push: ${{ github.event_name != 'pull_request' }} + tags: teamfemrdev/teamfemr:latest diff --git a/Dockerfile b/Dockerfile index 3b03f6931..ea6e2a0f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM sbtscala/scala-sbt:eclipse-temurin-jammy-8u352-b08_1.9.0_2.12.17 AS builder #build varaibles #ENV SBT_VERSION 1.1.5 -ENV PROJECT_HOME /usr/src +ENV PROJECT_HOME=/usr/src #RUN mkdir -p $PROJECT_HOME/activator $PROJECT_HOME/app @@ -22,28 +22,28 @@ RUN apt-get update && apt-get install -y \ # Install curl #RUN \ - # apt-get update && \ - # apt-get -y install curl +# apt-get update && \ +# apt-get -y install curl # Install sbt #RUN \ - #mkdir /working/ && \ - #cd /working/ && \ - #curl -L -o sbt-$SBT_VERSION.deb https://repo.scala-sbt.org/scalasbt/debian/sbt-$SBT_VERSION.deb && \ - #dpkg -i sbt-$SBT_VERSION.deb && \ - #rm sbt-$SBT_VERSION.deb && \ - #apt-get update && \ - #apt-get install sbt && \ - #cd && \ - #rm -r /working/ && \ - #sbt sbtVersion +#mkdir /working/ && \ +#cd /working/ && \ +#curl -L -o sbt-$SBT_VERSION.deb https://repo.scala-sbt.org/scalasbt/debian/sbt-$SBT_VERSION.deb && \ +#dpkg -i sbt-$SBT_VERSION.deb && \ +#rm sbt-$SBT_VERSION.deb && \ +#apt-get update && \ +#apt-get install sbt && \ +#cd && \ +#rm -r /working/ && \ +#sbt sbtVersion COPY Build.sbt . COPY project ./project RUN --mount=type=cache,target=/root/.ivy2 \ - --mount=type=cache,target=/root/.sbt \ - sbt update + --mount=type=cache,target=/root/.sbt \ + sbt update # Setup path variables and copy fEMR into container #ENV PATH $PROJECT_HOME/activator/activator-dist-1.3.10/bin:$PATH @@ -70,9 +70,9 @@ RUN apk add --no-cache bash python3 py3-pip gcc python3-dev musl-dev linux-heade RUN pip3 install psutil #database variables -ENV DB_URL "jdbc:mysql://localhost:3306/femr_db?characterEncoding=UTF-8&useSSL=false" -ENV DB_USER "username" -ENV DB_PASS "password" +ENV DB_URL="jdbc:mysql://localhost:3306/femr_db?characterEncoding=UTF-8&useSSL=false" +ENV DB_USER="username" +ENV DB_PASS="password" COPY --from=builder /usr/src/app/target/universal/femr-* /opt/bin/femr