From ad1051140993e81d96b055d4d631a0921e9e26ac Mon Sep 17 00:00:00 2001 From: erikarasnick Date: Thu, 4 Apr 2024 16:35:29 -0400 Subject: [PATCH 1/2] init GHA --- .github/workflows/build-deploy-pr.yaml | 40 ++++++++++++++++++++ .github/workflows/build-deploy-release.yaml | 42 +++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 .github/workflows/build-deploy-pr.yaml create mode 100644 .github/workflows/build-deploy-release.yaml diff --git a/.github/workflows/build-deploy-pr.yaml b/.github/workflows/build-deploy-pr.yaml new file mode 100644 index 0000000..e7c7781 --- /dev/null +++ b/.github/workflows/build-deploy-pr.yaml @@ -0,0 +1,40 @@ +name: build-deploy-pr +on: + pull_request: +jobs: + deploy-images: + runs-on: ubuntu-latest + env: + registry: ghcr.io + username: degauss-org + repository: daymet_chicago + strategy: + fail-fast: false + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: create latest tag variable + run: | + container="${{ env.registry }}/${{ env.username}}/${{ env.repository }}:latest" + echo "container=${container}" >> $GITHUB_ENV + - name: create pull request tag variable based on name of associated branch + if: github.event_name == 'pull_request' + run: | + versioned="${{ env.registry }}/${{ env.username}}/${{ env.repository }}:${GITHUB_HEAD_REF}" + echo "versioned=${versioned}" >> $GITHUB_ENV + - name: build container + run: | + docker build -t ${{ env.container }} . + - name: test run container + run: | + docker run --rm -v "${PWD}/test":/tmp ${{ env.container }} loyalty_degauss.csv + - name: login to ghcr + uses: docker/login-action@v1 + with: + registry: ${{ env.registry }} + username: ${{ env.username }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: deploy pull request container + run: | + docker tag ${{ env.container }} ${{ env.versioned }} + docker push ${{ env.versioned }} diff --git a/.github/workflows/build-deploy-release.yaml b/.github/workflows/build-deploy-release.yaml new file mode 100644 index 0000000..db06021 --- /dev/null +++ b/.github/workflows/build-deploy-release.yaml @@ -0,0 +1,42 @@ +name: build-deploy-release +on: + release: + types: [published] +jobs: + deploy-images: + runs-on: ubuntu-latest + env: + registry: ghcr.io + username: degauss-org + repository: daymet_chicago + strategy: + fail-fast: false + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: create latest tag variable + run: | + container="${{ env.registry }}/${{ env.username}}/${{ env.repository }}:latest" + echo "container=${container}" >> $GITHUB_ENV + - name: create release tag variable + if: github.event_name == 'release' + run: | + versioned="${{ env.registry }}/${{ env.username}}/${{ env.repository }}:${GITHUB_REF##*/}" + echo "versioned=${versioned}" >> $GITHUB_ENV + - name: build container + run: | + docker build -t ${{ env.container }} . + - name: test container + run: | + docker run --rm -v "${PWD}/test":/tmp ${{ env.container }} loyalty_degauss.csv + - name: login to ghcr + uses: docker/login-action@v1 + with: + registry: ${{ env.registry }} + username: ${{ env.username }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: deploy release (and latest) container + run: | + docker tag ${{ env.container }} ${{ env.versioned }} + docker push ${{ env.versioned }} + docker push ${{ env.container }} From 98c8d725e59ab0b24a90eca3b31a130b3e38210c Mon Sep 17 00:00:00 2001 From: erikarasnick Date: Fri, 5 Apr 2024 16:55:09 -0400 Subject: [PATCH 2/2] fix path to netcdf files --- Makefile | 26 +++++++++++++------------- entrypoint.R | 6 +++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 7ddc19b..bdfd0b9 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ -.PHONY: build test shell clean - -build: - docker build -t daymet_chicago . - -test: - docker run --rm -v "${PWD}":/tmp daymet_chicago loyalty_degauss.csv - -shell: - docker run --rm -it --entrypoint=/bin/bash -v "${PWD}":/tmp daymet_chicago - -clean: - docker system prune -f \ No newline at end of file +.PHONY: build test shell clean + +build: + docker build -t daymet_chicago . + +test: + docker run --rm -v "${PWD}/test":/tmp daymet_chicago loyalty_degauss.csv + +shell: + docker run --rm -it --entrypoint=/bin/bash -v "${PWD}":/tmp daymet_chicago + +clean: + docker system prune -f diff --git a/entrypoint.R b/entrypoint.R index a68a04c..5fc9d72 100644 --- a/entrypoint.R +++ b/entrypoint.R @@ -140,10 +140,10 @@ import_data <- function(.csv_filename = opt$filename, .min_lon = min_lon, .max_l return(out) } -# Creating function to load the Daymet NetCDF data +# Create function to load the Daymet NetCDF data daymet_load <- function() { # Loading the NetCDF files downloaded from Daymet as a SpatRaster raster stack - netcdf_list <- list.files(pattern = "_ncss.nc$") + netcdf_list <- list.files(path = "/app", pattern = "_ncss.nc$") # Initializing a time dictionary time_dict <- tibble(number = 1:365) for (i in 1:length(netcdf_list)) { @@ -154,7 +154,7 @@ daymet_load <- function() { layer_names <- as.character(1:365) layer_names <- paste0(dm_var, "_", layer_names, "_", yr) # Loading the Daymet data - daymet_load <- rast(netcdf_list[i]) + daymet_load <- rast(paste0("/app/", netcdf_list[i])) names(daymet_load) <- layer_names # Creating a dictionary to link numbers 1–365 to a date in a year (time dictionary) origin <- as_date(paste0(yr, "-01-01")) - 1 # Numbers count days since origin