Skip to content

Commit

Permalink
tests multi-stage building
Browse files Browse the repository at this point in the history
  • Loading branch information
jashapiro committed Apr 22, 2024
1 parent c880e71 commit d284843
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
49 changes: 47 additions & 2 deletions .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,41 @@ env:
IMAGE_NAME: alexslemonade/scpcatools

jobs:
build_and_push:
build_and_push_slim:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker login
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build slim image
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:docker"
file: scpcatools_slim.Dockerfile
tags: scpcatools-slim
outputs: type=docker,dest=/tmp/scpcatools-slim.tar # output for sharing
cache-from: type=gha
cache-to: type=gha

- name: Upload slim image artifact
uses: actions/upload-artifact@v3
with:
name: slim-image
path: /tmp/slim.tar

build_and_push_matrix:
runs-on: ubuntu-22.04
needs: build_and_push_slim
permissions:
contents: read
packages: write
Expand All @@ -28,7 +61,17 @@ jobs:
suffix: ""
- dockerfile: scpcatools_slim.Dockerfile
suffix: "-slim"

steps:
- name: Download slim image artifact
uses: actions/download-artifact@v3
with:
name: slim-image
path: /tmp

- name: Load slim image
run: docker load --input /tmp/scpcatools-slim.tar

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand All @@ -49,11 +92,13 @@ jobs:
type=semver,pattern={{raw}}
type=edge,branch=main
- uses: docker/build-push-action@v5
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:docker"
file: ${{ matrix.dockerfile }}
push: ${{ github.event_name == 'push' }}
outputs: type=docker,dest=/tmp/slim.tar # output for sharing
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
Expand Down
9 changes: 1 addition & 8 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
FROM bioconductor/r-ver:3.18
LABEL maintainer="[email protected]"
LABEL org.opencontainers.image.source https://github.com/AlexsLemonade/scpcaTools

#### R packages
# Use renv for R packages
ENV RENV_CONFIG_CACHE_ENABLED FALSE
RUN Rscript -e "install.packages(c('remotes', 'renv'))"
FROM scpcatools-slim

WORKDIR /usr/local/renv
COPY renv.lock renv.lock
Expand Down
2 changes: 1 addition & 1 deletion docker/scpcatools_slim.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM bioconductor/r-ver:3.18
FROM bioconductor/r-ver:3.18 AS scpcatools-slim
LABEL maintainer="[email protected]"
LABEL org.opencontainers.image.source https://github.com/AlexsLemonade/scpcaTools
LABEL org.opencontainers.image.title "scpcatools-slim"
Expand Down

0 comments on commit d284843

Please sign in to comment.