Merge pull request 'Add artifactapi_remote_github_alpine resource' (#17) from benvin/apk-github into main
ci/woodpecker/tag/release Pipeline was successful
ci/woodpecker/tag/release Pipeline was successful
Reviewed-on: #17
This commit was merged in pull request #17.
This commit is contained in:
@@ -65,6 +65,7 @@ Available resource types:
|
||||
- `artifactapi_remote_goproxy`
|
||||
- `artifactapi_remote_github_rpm`
|
||||
- `artifactapi_remote_github_deb`
|
||||
- `artifactapi_remote_github_alpine`
|
||||
|
||||
#### Common Attributes
|
||||
|
||||
@@ -96,11 +97,11 @@ Available resource types:
|
||||
| `ban_tags_enabled` | `false` | Enable tag banning |
|
||||
| `ban_tags` | | List of tags to ban |
|
||||
|
||||
#### Terraform / github_rpm / github_deb-specific Attributes
|
||||
#### Terraform / github_rpm / github_deb / github_alpine-specific Attributes
|
||||
|
||||
| Attribute | Default | Description |
|
||||
|-------------------|---------|----------------------------------------------------------|
|
||||
| `releases_remote` | `""` | Name of a backend remote that serves the download bytes. Terraform uses it for download URL rewriting; `github_rpm`/`github_deb` 302-redirect `.rpm`/`.deb` downloads to it. |
|
||||
| `releases_remote` | `""` | Name of a backend remote that serves the download bytes. Terraform uses it for download URL rewriting; `github_rpm`/`github_deb`/`github_alpine` 302-redirect `.rpm`/`.deb`/`.apk` downloads to it. |
|
||||
|
||||
#### github_rpm-specific notes
|
||||
|
||||
@@ -125,6 +126,19 @@ generic `github.com` remote that streams the `.deb` bytes; `.deb` downloads
|
||||
higher API rate limits. See
|
||||
`examples/resources/artifactapi_remote_github_deb/main.tf`.
|
||||
|
||||
#### github_alpine-specific notes
|
||||
|
||||
`artifactapi_remote_github_alpine` is the Alpine/apk analog of `github_rpm`: it
|
||||
exposes a GitHub repo's release `.apk` assets as an `apk` repository, synthesizing
|
||||
the apk index (`APKINDEX.tar.gz`) from release metadata without precaching
|
||||
packages. Set `base_url` to the releases API root
|
||||
(`https://api.github.com/repos/{owner}/{repo}`) and `releases_remote` to a
|
||||
generic `github.com` remote that streams the `.apk` bytes; `.apk` downloads
|
||||
302-redirect there. `patterns` filters which release assets become packages
|
||||
(regex on asset filename). `password` may hold a token for private repos or
|
||||
higher API rate limits. See
|
||||
`examples/resources/artifactapi_remote_github_alpine/main.tf`.
|
||||
|
||||
#### Example
|
||||
|
||||
```hcl
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
artifactapi = {
|
||||
source = "git.unkin.net/unkin/artifactapi"
|
||||
version = "0.0.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "artifactapi" {
|
||||
endpoint = "https://artifactapi.example.com"
|
||||
}
|
||||
|
||||
# Backend generic remote that serves the actual .apk bytes from github.com.
|
||||
# Its patterns must allowlist the target repo's release-download assets.
|
||||
resource "artifactapi_remote_generic" "github" {
|
||||
name = "github"
|
||||
base_url = "https://github.com"
|
||||
|
||||
patterns = [
|
||||
"goodtune/ghp/releases/download/.*\\.apk$",
|
||||
]
|
||||
}
|
||||
|
||||
# Metadata-only remote: scans goodtune/ghp releases for .apk assets and serves a
|
||||
# synthesized apk repo (APKINDEX). Packages are never precached; downloads
|
||||
# 302-redirect to the "github" remote above.
|
||||
resource "artifactapi_remote_github_alpine" "goodtune_ghp" {
|
||||
name = "goodtune-ghp"
|
||||
base_url = "https://api.github.com/repos/goodtune/ghp"
|
||||
description = "goodtune/ghp GitHub releases as an apk repo"
|
||||
releases_remote = artifactapi_remote_generic.github.name
|
||||
|
||||
mutable_ttl = 3600
|
||||
|
||||
# Optional: restrict which release assets become packages.
|
||||
patterns = [
|
||||
".*_x86_64\\.apk$",
|
||||
".*_noarch\\.apk$",
|
||||
]
|
||||
|
||||
# Optional: token for private repos / higher GitHub API rate limits.
|
||||
# password = var.github_token
|
||||
}
|
||||
@@ -70,6 +70,7 @@ func (p *ArtifactAPIProvider) Resources(_ context.Context) []func() resource.Res
|
||||
newRemoteResource("goproxy"),
|
||||
newRemoteResource("github_rpm"),
|
||||
newRemoteResource("github_deb"),
|
||||
newRemoteResource("github_alpine"),
|
||||
NewVirtualResource,
|
||||
NewLocalTerraformResource,
|
||||
NewLocalPyPIResource,
|
||||
|
||||
@@ -67,7 +67,7 @@ func TestProvider_Resources(t *testing.T) {
|
||||
resources := p.Resources(context.Background())
|
||||
|
||||
// 13 remote resource types + 1 virtual + local_terraform/pypi/rpm/deb/alpine/docker/generic = 21
|
||||
expectedCount := 21
|
||||
expectedCount := 22
|
||||
if len(resources) != expectedCount {
|
||||
t.Fatalf("expected %d resources, got %d", expectedCount, len(resources))
|
||||
}
|
||||
@@ -109,6 +109,7 @@ func TestProvider_Resources_ContainsExpectedTypes(t *testing.T) {
|
||||
"artifactapi_remote_goproxy",
|
||||
"artifactapi_remote_github_rpm",
|
||||
"artifactapi_remote_github_deb",
|
||||
"artifactapi_remote_github_alpine",
|
||||
"artifactapi_virtual",
|
||||
"artifactapi_local_terraform",
|
||||
"artifactapi_local_pypi",
|
||||
|
||||
@@ -69,6 +69,9 @@ func NewRemoteTerraform() resource.Resource { return &remoteResource{packageType
|
||||
func NewRemoteGoProxy() resource.Resource { return &remoteResource{packageType: "goproxy"} }
|
||||
func NewRemoteGitHubRPM() resource.Resource { return &remoteResource{packageType: "github_rpm"} }
|
||||
func NewRemoteGitHubDeb() resource.Resource { return &remoteResource{packageType: "github_deb"} }
|
||||
func NewRemoteGitHubAlpine() resource.Resource {
|
||||
return &remoteResource{packageType: "github_alpine"}
|
||||
}
|
||||
|
||||
func (r *remoteResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_remote_" + r.packageType
|
||||
@@ -148,7 +151,7 @@ func (r *remoteResource) Schema(_ context.Context, _ resource.SchemaRequest, res
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"releases_remote": schema.StringAttribute{
|
||||
Description: "Name of a backend remote that serves the actual download bytes. Used by the terraform remote (download URL rewriting) and the github_rpm/github_deb remotes (302 redirect of .rpm/.deb downloads to a generic github.com remote).",
|
||||
Description: "Name of a backend remote that serves the actual download bytes. Used by the terraform remote (download URL rewriting) and the github_rpm/github_deb/github_alpine remotes (302 redirect of .rpm/.deb/.apk downloads to a generic github.com remote).",
|
||||
Optional: true, Computed: true, Default: stringdefault.StaticString(""),
|
||||
},
|
||||
"upstream_dial_timeout": schema.Int64Attribute{
|
||||
|
||||
@@ -411,6 +411,7 @@ func TestRemoteResource_Metadata(t *testing.T) {
|
||||
{"npm", "artifactapi_remote_npm"},
|
||||
{"github_rpm", "artifactapi_remote_github_rpm"},
|
||||
{"github_deb", "artifactapi_remote_github_deb"},
|
||||
{"github_alpine", "artifactapi_remote_github_alpine"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -523,6 +524,7 @@ func TestNewRemoteResource_Constructors(t *testing.T) {
|
||||
{"goproxy", func() resource.Resource { return NewRemoteGoProxy() }, "goproxy"},
|
||||
{"github_rpm", func() resource.Resource { return NewRemoteGitHubRPM() }, "github_rpm"},
|
||||
{"github_deb", func() resource.Resource { return NewRemoteGitHubDeb() }, "github_deb"},
|
||||
{"github_alpine", func() resource.Resource { return NewRemoteGitHubAlpine() }, "github_alpine"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user