diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml index 71e4ac8..82e62a6 100644 --- a/.github/workflows/lint_and_test.yml +++ b/.github/workflows/lint_and_test.yml @@ -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/action-docker-layer-caching@v0.1.1 - continue-on-error: true - with: - key: ci-docker-cache-{hash} - restore-keys: | - ci-docker-cache- - layer-ci-docker-cache- + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Build and Run Docker image + - name: Build docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./docker/dev.Dockerfile + load: true + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Run Docker image run: docker compose up --detach # NOTE: All exec commands use the -T flag to compensate for @@ -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: | diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index 4ada043..bf26c4b 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -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 diff --git a/docker/dev.Dockerfile b/docker/dev.Dockerfile index e7c54d4..3ebddd3 100644 --- a/docker/dev.Dockerfile +++ b/docker/dev.Dockerfile @@ -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 \ @@ -23,31 +23,28 @@ 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 @@ -55,7 +52,8 @@ 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"