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

Support tagging the image #141

Closed
gaetan-craft opened this issue Jan 26, 2024 · 1 comment · Fixed by #184
Closed

Support tagging the image #141

gaetan-craft opened this issue Jan 26, 2024 · 1 comment · Fixed by #184
Assignees

Comments

@gaetan-craft
Copy link

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

It would be nice to be able to add tags to the created image which would help further search of the app

Use Case(s)

get all image build with a given version for example

Potential configuration

image_tags = list(string)

Potential References

@gaetan-craft
Copy link
Author

I circumvent this by using post-processor. Here is the code I use to do this if someone finding this issue want to do it.
In the hcl file

locals {
  tags = {
    Name      = "base app ${var.version} webserver ${var.webserver} {{ timestamp }}"
    Version   = var.version
    Vector    = var.vector_version
  }
}

build {
  name    = "scaleway"
  sources = ["source.scaleway.base"]
  post-processor "manifest" {
    output     = "manifest.json"
    strip_path = true
  }
  post-processor "shell-local" {
    script = "scripts/tag-scaleway-image.sh"
    env    = merge({ image_tags = join(" ", keys(local.tags)) }, local.tags)
  }
  post-processor "shell-local" {
    inline = ["rm manifest.json"]
  }
}

the tag-scaleway-image.sh script

#!/bin/bash

set -eo pipefail

if [ ! -e manifest.json ]; then
  echo "no manifest"
  exit 1
fi

artifact_id=$(jq -r '.builds|first.artifact_id' manifest.json)
image_id=${artifact_id##*:}
declare -a args
i=0
for tag in ${image_tags?"image tags env variable should be passed"}; do
  args[$i]="tags.$i='$tag:${!tag}'"
  ((i+=1))
done
scw instance image update "$image_id" "${args[@]}"

@yfodil yfodil linked a pull request Jul 12, 2024 that will close this issue
@yfodil yfodil closed this as completed Jul 12, 2024
@yfodil yfodil self-assigned this Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants