tests/testthat/test-dockerbuild.R

n_temp <- tempdir()
file.copy("renv.lock", n_temp)
withr::with_dir(
  n_temp,
  {
    test_that("dockerfile is buildable", {
      # descdir <- tempfile(pattern = "desc")
      # dir.create(descdir)
      # file.copy("DESCRIPTION", descdir)
      my_dock <- dock_from_renv(lockfile = "renv.lock")
      cat(".RData
.Rhistory
.git
.gitignore
manifest.json
rsconnect/
.Rproj.user", file = ".dockerignore")
      # file.edit(".dockerignore")
      my_dock$write("Dockerfile")



      skip_on_cran()
      out_v <- system("docker -v")
      skip_if_not(out_v == 0) # docker not available

      out_linux <- system("docker run rocker/r-base")

      skip_if_not(out_linux == 2) # image operating system "linux" cannot be used on this platform

      out1 <- system("docker run hello-world ")
      expect_equal(out1, 0)

      out <- system("docker build . --file Dockerfile ", wait = TRUE)
      # file.edit(tpf)
      expect_equal(out, 0)

      unlink(".dockerignore")
    })
  }
)
ColinFay/dockerfiler documentation built on Nov. 16, 2023, 8:33 p.m.