Skip to content

Commit

Permalink
[Dev] Fix CI caching (kieraneglin#325)
Browse files Browse the repository at this point in the history
* Consolidated dockerfile commands

* Added teardown step

* FIxed typo

* Got rid of old caching action

* Added buildx

* Added steps for compiling test ENV to dockerfile

* Changed the order of things

* Added env vars

* more env vars

* Removed step

* No compile flag

* fetch quest

* Removed other thing

* volumes

* Rolling back some other changes

* more consolidation

* updated checkout runner
  • Loading branch information
kieraneglin authored Jul 17, 2024
1 parent 029981b commit 8dd8e49
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
25 changes: 14 additions & 11 deletions .github/workflows/lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ jobs:
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
env:
COMPOSE_FILE: ./docker-compose.ci.yml
MIX_ENV: test

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Pull prebuilt images
run: docker compose pull

- name: Setup Docker layer caching
uses: jpribyl/[email protected]
continue-on-error: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build docker image
uses: docker/build-push-action@v5
with:
key: ci-docker-cache-{hash}
restore-keys: |
ci-docker-cache-
layer-ci-docker-cache-
context: .
file: ./docker/dev.Dockerfile
load: true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build and Run Docker image
- name: Run Docker image
run: docker compose up --detach

# NOTE: All exec commands use the -T flag to compensate for
Expand All @@ -43,8 +47,7 @@ jobs:
# See https://github.com/actions/runner/issues/241 and https://github.com/docker/compose/issues/8537
- name: Install Elixir and JS deps
run: |
docker compose exec -T phx yarn install && cd assets && yarn install && cd ..
docker compose exec -T phx mix deps.get
docker compose exec -T phx mix deps.get && yarn install && cd assets && yarn install && cd ..
- name: Create and Migrate database
run: |
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ services:
- MIX_ENV=test
volumes:
- '.:/app'
# These lines ensure the deps can be saved as build artifacts for caching
- '/app/deps'
- '/app/_build'
ports:
- '4008:4008'
command: tail -F /dev/null
52 changes: 25 additions & 27 deletions docker/dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ ARG TARGETPLATFORM
RUN echo "Building for ${TARGETPLATFORM:?}"

# Install debian packages
RUN apt-get update -qq
RUN apt-get install -y inotify-tools curl git openssh-client jq \
python3 python3-setuptools python3-wheel python3-dev pipx \
python3-mutagen locales procps build-essential graphviz
RUN apt-get update -qq && \
apt-get install -y inotify-tools curl git openssh-client jq \
python3 python3-setuptools python3-wheel python3-dev pipx \
python3-mutagen locales procps build-essential graphviz

# Install ffmpeg
RUN export FFMPEG_DOWNLOAD=$(case ${TARGETPLATFORM:-linux/amd64} in \
Expand All @@ -23,39 +23,37 @@ RUN export FFMPEG_DOWNLOAD=$(case ${TARGETPLATFORM:-linux/amd64} in \
tar -xf /tmp/ffmpeg.tar.xz --strip-components=2 --no-anchored -C /usr/bin/ "ffmpeg" && \
tar -xf /tmp/ffmpeg.tar.xz --strip-components=2 --no-anchored -C /usr/bin/ "ffprobe"

# Install nodejs
RUN curl -sL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt-get install nodejs
RUN npm install -g yarn

# Install baseline Elixir packages
RUN mix local.hex --force
RUN mix local.rebar --force

# Download and update YT-DLP
RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
RUN chmod a+rx /usr/local/bin/yt-dlp
RUN yt-dlp -U

# Install Apprise
RUN export PIPX_HOME=/opt/pipx && \
export PIPX_BIN_DIR=/usr/local/bin && \
pipx install apprise
# Install nodejs and Yarn
RUN curl -sL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh && \
bash nodesource_setup.sh && \
apt-get install -y nodejs && \
npm install -g yarn && \
# Install baseline Elixir packages
mix local.hex --force && \
mix local.rebar --force && \
# Download and update YT-DLP
curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp && \
chmod a+rx /usr/local/bin/yt-dlp && \
yt-dlp -U && \
# Install Apprise
export PIPX_HOME=/opt/pipx && \
export PIPX_BIN_DIR=/usr/local/bin && \
pipx install apprise

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

# Create app directory and copy the Elixir projects into it.
WORKDIR /app
COPY . ./

# Install Elixir deps
# RUN mix archive.install github hexpm/hex branch latest
RUN mix deps.get
RUN MIX_ENV=dev mix deps.get && MIX_ENV=dev mix deps.compile
RUN MIX_ENV=test mix deps.get && MIX_ENV=test mix deps.compile
# Gives us iex shell history
ENV ERL_AFLAGS="-kernel shell_history enabled"

Expand Down

0 comments on commit 8dd8e49

Please sign in to comment.