generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding container args as well as improving docs (#9)
* Adding container args as well as improving docs * The version cannot be used as an input * Picking a different (easier) package and not pulling image * Using a different version of slurmR for the test * Adding tag as an output * Got the names wrong for the tags * Should put the built info in the second buidl * Removing the container image for test * Renaming SHA to GH_SHA in build context * Wrong names * Re-correcting tag names * Needed to add double quotes to the image * Trying alternative approach * Adding checkout to the second job * Checking if renaming the image works * Trying with other type of labe * Adding makefile and fixing example
- Loading branch information
Showing
6 changed files
with
121 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,9 @@ flowchart LR | |
Containerfile2-->|Generates|Image2 | ||
``` | ||
|
||
Caching is done using the [actions/cache](https://github.com/actions/cache/tree/v4) (lookup only) and [docker/build-push-action](https://github.com/docker/build-push-action) actions. Users have to explicitly provide the cache key for the first step. For example, if you are dealing with an R package, you can cache the dependencies by passing the key `${{ hashFiles('DESCRIPTION') }}` to the `first-step-cache-key` input. That way, the first step will only be executed if the dependencies change. | ||
Caching is done using the [actions/cache](https://github.com/actions/cache/tree/v4) (lookup only) and [docker/build-push-action@v6](https://github.com/docker/build-push-action/tree/v6) actions. Users have to explicitly provide the cache key for the first step. For example, if you are dealing with an R package, you can cache the dependencies by passing the key `${{ hashFiles('DESCRIPTION') }}` to the `first-step-cache-key` input. That way, the first step will only be executed if the dependencies change. | ||
|
||
## Inputs | ||
## Inputs and Outputs | ||
|
||
| Field | Description | Required | Default | | ||
|-------|-------------|----------|---------| | ||
|
@@ -24,8 +24,23 @@ Caching is done using the [actions/cache](https://github.com/actions/cache/tree/ | |
| `registry` | Registry to push the image to | true | | | ||
| `main-branch-name` | Name of the main branch | false | `'main'` | | ||
| `main-branch-tag` | Tag to use for the main branch | false | `'latest'` | | ||
|
||
The following are arguments passed to the [docker/build-push-action@v6](https://github.com/docker/build-push-action/tree/v6) action. | ||
|
||
| Field | Description | Required | Default | | ||
|-------|-------------|----------|---------| | ||
| `push-image-1` | Push the image created during the first step | false | `false` | | ||
| `push-image-2` | Push the image created during the second step | false | `false` | | ||
| `build-args-1` | Build arguments for the first step | false | | | ||
| `build-args-2` | Build arguments for the second step | false | | | ||
|
||
The action has the following outputs: | ||
|
||
| Field | Description | | ||
|-------|-------------| | ||
| `tag` | Container tag of the built image | | ||
| `branch` | Branch name | | ||
|
||
|
||
## Example: Using ghcr.io | ||
|
||
|
@@ -56,7 +71,7 @@ jobs: | |
name: Checkout code | ||
|
||
- name: Two-step build | ||
uses: ./[email protected] | ||
uses: CDCgov/cfa-actions/[email protected] | ||
with: | ||
# Login information | ||
registry: ghcr.io/ | ||
|
@@ -91,7 +106,7 @@ CMD ["bash"] | |
[`Containerfile`](examples/Containerfile) | ||
|
||
```Containerfile | ||
ARG TAG=latest | ||
ARG TAG=dependencies-latest | ||
|
||
FROM ghcr.io/cdcgov/cfa-actions:${TAG} | ||
|
||
|
@@ -100,4 +115,4 @@ COPY twostep-container-build/example/Containerfile /app/. | |
CMD ["bash"] | ||
``` | ||
|
||
Notice the `TAG` argument which is passed to the second container file. During runs of the action, `TAG` takes the value of the branch name or `latest` if the branch is the main branch. | ||
Notice the `TAG` argument which is passed to the second container file. During runs of the action, `TAG` takes the value of the `dependencies-[branch name]` or `dependencies-latest` if the branch is the main branch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
ARG TAG=latest | ||
ARG TAG=dependencies-latest | ||
ARG IMAGE=ghcr.io/cdcgov/cfa-actions | ||
|
||
FROM ghcr.io/cdcgov/cfa-actions:${TAG} | ||
FROM ${IMAGE}:${TAG} | ||
|
||
COPY twostep-container-build/examples/Containerfile /app/. | ||
# Notice that ARG are reset after the FROM | ||
ARG GH_SHA=default_var | ||
LABEL GH_SHA=${GH_SHA} | ||
|
||
COPY . /app/. | ||
CMD ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
FROM rocker/r-base:4.4.0 | ||
|
||
RUN install2.r epiworldR | ||
|
||
FROM python:3.12 | ||
CMD ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
ifndef TAG | ||
TAG := latest | ||
endif | ||
|
||
ifndef IMAGE | ||
IMAGE := ghcr.io/cdcgov/cfa-actions | ||
endif | ||
|
||
ifndef ENGINE | ||
ENGINE := podman | ||
endif | ||
|
||
deps: | ||
$(ENGINE) build \ | ||
--no-cache \ | ||
-t $(IMAGE):dependencies-$(TAG) -f Containerfile.dependencies | ||
|
||
build: | ||
cd ../../ && \ | ||
$(ENGINE) build \ | ||
--build-arg TAG=dependencies-$(TAG) \ | ||
--build-arg GH_SHA=example \ | ||
--build-arg IMAGE=$(IMAGE) \ | ||
--no-cache \ | ||
-t $(IMAGE):$(TAG) \ | ||
-f twostep-container-build/examples/Containerfile | ||
|
||
print-sha: | ||
$(ENGINE) inspect $(IMAGE):$(TAG) --format='{{json .Config.Labels}}' | jq . |