Skip to content

Commit

Permalink
Merge pull request #752 from FEMR/karan
Browse files Browse the repository at this point in the history
Workflow that actually caches the dependencies for docker build.
  • Loading branch information
realkaranvir authored Dec 6, 2024
2 parents 0c7b7ef + 37e0c5b commit 75e0a99
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 57 deletions.
64 changes: 25 additions & 39 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,50 @@ name: Docker Image CI/CD

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
push_to_registry:
name: Push Docker Image to Docker Hub
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/[email protected]
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
36 changes: 18 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 75e0a99

Please sign in to comment.