Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/service image name #212

Merged
merged 43 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
690732d
fix(service): remove image name suppres func
mavogel Jun 1, 2021
fafe7da
test(service): use sha256@hash now
mavogel Jun 1, 2021
23b079f
docs(readme): add creation of service
mavogel Jun 1, 2021
d9f9aa2
docs: fix spelling error
mavogel Jun 1, 2021
0c622d6
chore: remove website-lint containers after run
mavogel Jun 1, 2021
5698899
docs: run website lint-fix
mavogel Jun 1, 2021
47c0bac
docs: regenerate website
mavogel Jun 1, 2021
9467247
docs: clarifies image ID attribute
mavogel Jun 2, 2021
3c11077
feat: add docker image data-source
mavogel Jun 2, 2021
982bb21
docs(service): add example for iamge datasource usage
mavogel Jun 2, 2021
a6bdbdc
test(service): fix test for image digests
mavogel Jun 2, 2021
16d4e4a
chore: add todo for retries on image removal
mavogel Jun 2, 2021
758274e
fix: service tests
mavogel Jun 2, 2021
cf0e9c4
feat: add sha256_digest attribute to image
mavogel Jun 2, 2021
5ef1ada
test: for ds image and non existent tags
mavogel Jun 2, 2021
461ca4b
chore: rum terraform fmt
mavogel Jun 2, 2021
77387dc
docs: regenerate websitee
mavogel Jun 2, 2021
8098d5e
fix(service): force remove images in tests
mavogel Jun 2, 2021
897b944
chore(ci): debug flaky service test
mavogel Jun 2, 2021
12ab902
fix(service): test to pull images upfront
mavogel Jun 3, 2021
af86a10
Revert "chore(ci): debug flaky service test"
mavogel Jun 3, 2021
1f7249d
chore: remove break comment
mavogel Jun 8, 2021
dcabdd0
fix(service): update specs to use full image name
mavogel Jun 8, 2021
19528e6
feat: add repo digest for image with fallback to ID
mavogel Jun 8, 2021
a46ec7f
docs: regenerate website
mavogel Jun 8, 2021
b0cb9c3
chore: replace deprecated image latest attribute with id
mavogel Jun 14, 2021
61487f5
chore: replace more deprecated image latest attribute with id
mavogel Jun 14, 2021
0659e2c
fix: remove latest attr of newly introduces image data source
mavogel Jun 14, 2021
8a9138c
fix: remove fallback from repo digest determination. use empty string…
mavogel Jun 14, 2021
53b173f
Revert "chore: replace more deprecated image latest attribute with id"
mavogel Jun 14, 2021
8e09d0d
Revert "chore: replace deprecated image latest attribute with id"
mavogel Jun 14, 2021
42bf204
fix: linter
mavogel Jun 14, 2021
d30d29a
fix: test for removed latest attr
mavogel Jun 14, 2021
abbfbcc
docs: add edge case for docker image ds
mavogel Jun 14, 2021
3393d6c
docs(service): add image name and digest options
mavogel Jun 17, 2021
7e439c7
fix: image repo digest with tag determination
mavogel Jun 17, 2021
17c9ed9
fix: always return a repoDigest
mavogel Jun 17, 2021
799aa44
fix(image): deprecation notice for latest attribute
mavogel Jun 20, 2021
e1a25cb
docs(readme): use repo_digest for service image
mavogel Jun 20, 2021
827d44a
fix(service): use repo_digest attribute in tests
mavogel Jun 20, 2021
fb9273d
chore(build): remove flaky failing mod download on setup
mavogel Jun 20, 2021
0ff8fc9
fix(ci): explicitly go get tfplugindocs
mavogel Jun 20, 2021
f0c057a
fix(ci): remove gocenter.io proxy
mavogel Jun 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/acc-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- '.github/workflows/**'

env:
GOPROXY: https://proxy.golang.org,https://gocenter.io,direct
GOPROXY: https://proxy.golang.org,direct
DEBIAN_FRONTEND: noninteractive
DOCKER_CE_VERSION: "5:20.10.5~3-0~ubuntu-focal"
GO_VERSION: "1.16"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- '.github/workflows/**'

env:
GOPROXY: https://proxy.golang.org,https://gocenter.io,direct
GOPROXY: https://proxy.golang.org,direct
GO_VERSION: "1.16"

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- '.github/workflows/**'

env:
GOPROXY: https://proxy.golang.org,https://gocenter.io,direct
GOPROXY: https://proxy.golang.org,direct
GO_VERSION: "1.16"

jobs:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/website-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- docs/**

env:
GOPROXY: https://proxy.golang.org,https://gocenter.io,direct
GOPROXY: https://proxy.golang.org,direct
GO_VERSION: "1.16"

jobs:
Expand All @@ -24,6 +24,8 @@ jobs:
go-version: ${{ env.GO_VERSION }}
- name: Setup tools
run: make setup
- name: Explicitly get tfplugindocs
run: go get github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
- name: Generate the website
run: make website-generation
- name: Verify Changed files
Expand Down
5 changes: 2 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ build: fmtcheck
go install

setup:
go mod download
cd tools && GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
cd tools && GO111MODULE=on go install github.com/katbyte/terrafmt
cd tools && GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint
Expand Down Expand Up @@ -76,7 +75,7 @@ website-lint:
echo "Unexpected mispelling found in website files."; \
echo "To automatically fix the misspelling, run 'make website-lint-fix' and commit the changes."; \
exit 1)
@docker run -v $(PWD):/markdown 06kellyjac/markdownlint-cli docs/ || (echo; \
@docker run --rm -v $(PWD):/markdown 06kellyjac/markdownlint-cli docs/ || (echo; \
echo "Unexpected issues found in website Markdown files."; \
echo "To apply any automatic fixes, run 'make website-lint-fix' and commit the changes."; \
exit 1)
Expand All @@ -89,7 +88,7 @@ website-lint:
website-lint-fix:
@echo "==> Applying automatic website linter fixes..."
@misspell -w -source=text docs/
@docker run -v $(PWD):/markdown 06kellyjac/markdownlint-cli --fix docs/
@docker run --rm -v $(PWD):/markdown 06kellyjac/markdownlint-cli --fix docs/
@terrafmt fmt ./docs --pattern '*.md'

.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile website-link-check website-lint website-lint-fix
Expand Down
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ terraform {
# since new versions are released frequently
docker = {
source = "kreuzwerker/docker"
version = "2.12.1"
version = "2.12.2"
}
}
}
Expand All @@ -42,9 +42,38 @@ resource "docker_image" "nginx" {
}

# Create a docker container resource
# -> same as 'docker run --name nginx -d nginx:latest'
# -> same as 'docker run --name nginx -p8080:80 -d nginx:latest'
resource "docker_container" "nginx" {
name = "nginx"
image = docker_image.nginx.latest
mavogel marked this conversation as resolved.
Show resolved Hide resolved

ports {
external = 8080
internal = 80
}
}

# Or create a service resource
# -> same as 'docker service create -d -p 8081:80 --name nginx-service --replicas 2 nginx:latest'
resource "docker_service" "nginx_service" {
name = "nginx-service"
task_spec {
container_spec {
image = docker_image.nginx.repo_digest
}
}

mode {
replicated {
replicas = 2
}
}

endpoint_spec {
ports {
published_port = 8081
target_port = 80
}
}
}
```
52 changes: 52 additions & 0 deletions docs/data-sources/image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "docker_image Data Source - terraform-provider-docker"
subcategory: ""
description: |-
docker_image provides details about a specific Docker Image which need to be presend on the Docker Host
---

# docker_image (Data Source)

`docker_image` provides details about a specific Docker Image which need to be presend on the Docker Host

## Example Usage

```terraform
# uses the 'latest' tag
data "docker_image" "latest" {
name = "nginx"
}

# uses a specific tag
data "docker_image" "specific" {
name = "nginx:1.17.6"
}

# use the image digest
data "docker_image" "digest" {
name = "nginx@sha256:36b74457bccb56fbf8b05f79c85569501b721d4db813b684391d63e02287c0b2"
}

# uses the tag and the image digest
data "docker_image" "tag_and_digest" {
name = "nginx:1.19.1@sha256:36b74457bccb56fbf8b05f79c85569501b721d4db813b684391d63e02287c0b2"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- **name** (String) The name of the Docker image, including any tags or SHA256 repo digests.

### Optional

- **id** (String) The ID of this resource.
mavogel marked this conversation as resolved.
Show resolved Hide resolved

### Read-Only

- **repo_digest** (String) The image sha256 digest in the form of `repo[:tag]@sha256:<hash>`. It may be empty in the edge case where the local image was pulled from a repo, tagged locally, and then referred to in the data source by that local name/tag.


11 changes: 6 additions & 5 deletions docs/resources/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ resource "docker_image" "ubuntu" {

### Dynamic updates

To be able to update an update dynamically when the `sha256` sum changes,
To be able to update an image dynamically when the `sha256` sum changes,
you need to use it in combination with `docker_registry_image` as follows:

```terraform
Expand All @@ -43,8 +43,8 @@ resource "docker_image" "ubuntu" {

### Build

You can also use the resource to build and image.
In thid case the image "zoo" and "zoo:develop" are built.
You can also use the resource to build an image.
In this case the image "zoo" and "zoo:develop" are built.

```terraform
resource "docker_image" "zoo" {
Expand Down Expand Up @@ -80,8 +80,9 @@ resource "docker_image" "zoo" {

### Read-Only

- **latest** (String) The ID of the image.
- **latest** (String, Deprecated) The ID of the image in the form of `sha256:<hash>` image digest. Do not confuse it with the default `latest` tag.
- **output** (String, Deprecated)
- **repo_digest** (String) The image sha256 digest in the form of `repo[:tag]@sha256:<hash>`.

<a id="nestedblock--build"></a>
### Nested Schema for `build`
Expand All @@ -99,4 +100,4 @@ Optional:
- **no_cache** (Boolean) Do not use cache when building the image
- **remove** (Boolean) Remove intermediate containers after a successful build. Defaults to `true`.
- **tag** (List of String) Name and optionally a tag in the 'name:tag' format
- **target** (String) Set the target build stage to build
- **target** (String) Set the target build stage to build
29 changes: 28 additions & 1 deletion docs/resources/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ The following command is the equivalent:
docker service create -d -p 8080 --name foo-service repo.mycompany.com:8080/foo-service:v1
```

### Basic with Datasource

Alternatively, if the image is already present on the Docker Host and not managed
by `terraform`, you can also use the `docker_image` datasource:

```terraform
data "docker_image" "foo" {
name = "repo.mycompany.com:8080/foo-service:v1"
}

resource "docker_service" "foo" {
name = "foo-service"

task_spec {
container_spec {
image = data.docker_image.foo.repo_digest
}
}

endpoint_spec {
ports {
target_port = "8080"
}
}
}
```

### Advanced

The following configuration shows the full capabilities of a Docker Service,
Expand Down Expand Up @@ -307,7 +334,7 @@ Optional:

Required:

- **image** (String) The image name to use for the containers of the service
- **image** (String) The image name to use for the containers of the service, like `nginx:1.17.6`. Also use the data-source or resource of `docker_image` with the `repo_digest` or `docker_registry_image` with the `name` attribute for this, as shown in the examples.

Optional:

Expand Down
19 changes: 19 additions & 0 deletions examples/data-sources/docker_image/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# uses the 'latest' tag
data "docker_image" "latest" {
name = "nginx"
}

# uses a specific tag
data "docker_image" "specific" {
name = "nginx:1.17.6"
}

# use the image digest
data "docker_image" "digest" {
name = "nginx@sha256:36b74457bccb56fbf8b05f79c85569501b721d4db813b684391d63e02287c0b2"
}

# uses the tag and the image digest
data "docker_image" "tag_and_digest" {
name = "nginx:1.19.1@sha256:36b74457bccb56fbf8b05f79c85569501b721d4db813b684391d63e02287c0b2"
}
19 changes: 19 additions & 0 deletions examples/resources/docker_service/resource-basic-image-ds.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
data "docker_image" "foo" {
name = "repo.mycompany.com:8080/foo-service:v1"
}

resource "docker_service" "foo" {
name = "foo-service"

task_spec {
container_spec {
image = data.docker_image.foo.repo_digest
}
}

endpoint_spec {
ports {
target_port = "8080"
}
}
}
3 changes: 2 additions & 1 deletion examples/resources/docker_service/resource-basic.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

resource "docker_service" "foo" {
name = "foo-service"

Expand All @@ -12,4 +13,4 @@ resource "docker_service" "foo" {
target_port = "8080"
}
}
}
}