Skip to content

Commit 3209af4

Browse files
Merge pull request #508 from drone-plugins/Remove-EoL-Components
fix: [CI-21707]: Remove EoL Components
2 parents 2f6803e + a58ca41 commit 3209af4

8 files changed

Lines changed: 175 additions & 140 deletions

File tree

.harness/harness.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pipeline:
3333
identifier: Run_1
3434
spec:
3535
connectorRef: Plugins_Docker_Hub_Connector
36-
image: golang:1.24.11
36+
image: golang:1.25.7
3737
shell: Sh
3838
command: go vet ./...
3939
- step:
@@ -42,7 +42,7 @@ pipeline:
4242
identifier: Run_2
4343
spec:
4444
connectorRef: Plugins_Docker_Hub_Connector
45-
image: golang:1.24.11
45+
image: golang:1.25.7
4646
shell: Sh
4747
command: go test -cover ./...
4848
- parallel:
@@ -70,7 +70,7 @@ pipeline:
7070
identifier: Build_Push
7171
spec:
7272
connectorRef: Plugins_Docker_Hub_Connector
73-
image: golang:1.24.11
73+
image: golang:1.25.7
7474
shell: Sh
7575
command: go build -a -tags netgo -o release/linux/amd64/drone-<+matrix.repo> ./cmd/drone-<+matrix.repo>
7676
envVariables:
@@ -157,7 +157,7 @@ pipeline:
157157
identifier: buildpush
158158
spec:
159159
connectorRef: Plugins_Docker_Hub_Connector
160-
image: golang:1.24.11
160+
image: golang:1.25.7
161161
shell: Sh
162162
command: go build -a -tags netgo -o release/linux/arm64/drone-<+matrix.repo> ./cmd/drone-<+matrix.repo>
163163
envVariables:

cmd/drone-acr/main.go

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"fmt"
88
"io/ioutil"
9+
"log/slog"
910
"net/http"
1011
"net/url"
1112
"os"
@@ -16,8 +17,6 @@ import (
1617
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
1718
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
1819
"github.com/joho/godotenv"
19-
"github.com/pkg/errors"
20-
"github.com/sirupsen/logrus"
2120

2221
docker "github.com/drone-plugins/drone-docker"
2322
azureutil "github.com/drone-plugins/drone-docker/internal/azure"
@@ -82,32 +81,35 @@ func main() {
8281
if username == "" && password == "" {
8382
// docker login credentials are not provided
8483
var err error
85-
username = defaultUsername
86-
if idToken != "" && clientId != "" && tenantId != "" {
87-
logrus.Debug("Using OIDC authentication flow")
88-
var aadToken string
89-
aadToken, err = azureutil.GetAADAccessTokenViaClientAssertion(context.Background(), tenantId, clientId, idToken, authorityHost)
90-
if err != nil {
91-
logrus.Fatal(err)
92-
}
84+
username = defaultUsername
85+
if idToken != "" && clientId != "" && tenantId != "" {
86+
slog.Debug("using OIDC authentication flow")
87+
var aadToken string
88+
aadToken, err = azureutil.GetAADAccessTokenViaClientAssertion(context.Background(), tenantId, clientId, idToken, authorityHost)
89+
if err != nil {
90+
slog.Error("failed to get AAD access token", "error", err)
91+
os.Exit(1)
92+
}
9393
var p string
9494
p, err = getPublicUrl(aadToken, registry, subscriptionId)
9595
if err == nil {
9696
publicUrl = p
9797
} else {
9898
fmt.Fprintf(os.Stderr, "failed to get public url with error: %s\n", err)
9999
}
100-
password, err = fetchACRToken(tenantId, aadToken, registry)
101-
if err != nil {
102-
logrus.Fatal(err)
103-
}
104-
} else {
105-
password, publicUrl, err = getAuth(clientId, clientSecret, clientCert, tenantId, subscriptionId, registry)
106-
if err != nil {
107-
logrus.Fatal(err)
108-
}
100+
password, err = fetchACRToken(tenantId, aadToken, registry)
101+
if err != nil {
102+
slog.Error("failed to fetch ACR token", "error", err)
103+
os.Exit(1)
104+
}
105+
} else {
106+
password, publicUrl, err = getAuth(clientId, clientSecret, clientCert, tenantId, subscriptionId, registry)
107+
if err != nil {
108+
slog.Error("failed to get auth", "error", err)
109+
os.Exit(1)
109110
}
110111
}
112+
}
111113

112114
// must use the fully qualified repo name. If the
113115
// repo name does not have the registry prefix we
@@ -133,7 +135,8 @@ func main() {
133135
cmd.Stderr = os.Stderr
134136
err := cmd.Run()
135137
if err != nil {
136-
logrus.Fatal(err)
138+
slog.Error("command execution failed", "error", err)
139+
os.Exit(1)
137140
}
138141
}
139142

@@ -153,26 +156,26 @@ func getAuth(clientId, clientSecret, clientCert, tenantId, subscriptionId, regis
153156
if clientCert != "" {
154157
err := setupACRCert(clientCert, acrCertPath)
155158
if err != nil {
156-
errors.Wrap(err, "failed to push setup cert file")
159+
slog.Warn("failed to push setup cert file", "error", err)
157160
}
158161
}
159162

160163
// Get AZ env
161164
if err := os.Setenv(clientIdEnv, clientId); err != nil {
162-
return "", "", errors.Wrap(err, "failed to set env variable client Id")
165+
return "", "", fmt.Errorf("failed to set env variable client Id: %w", err)
163166
}
164167
if err := os.Setenv(clientSecretKeyEnv, clientSecret); err != nil {
165-
return "", "", errors.Wrap(err, "failed to set env variable client secret")
168+
return "", "", fmt.Errorf("failed to set env variable client secret: %w", err)
166169
}
167170
if err := os.Setenv(tenantKeyEnv, tenantId); err != nil {
168-
return "", "", errors.Wrap(err, "failed to set env variable tenant Id")
171+
return "", "", fmt.Errorf("failed to set env variable tenant Id: %w", err)
169172
}
170173
if err := os.Setenv(certPathEnv, acrCertPath); err != nil {
171-
return "", "", errors.Wrap(err, "failed to set env variable cert path")
174+
return "", "", fmt.Errorf("failed to set env variable cert path: %w", err)
172175
}
173176
env, err := azidentity.NewEnvironmentCredential(nil)
174177
if err != nil {
175-
return "", "", errors.Wrap(err, "failed to get env credentials from azure")
178+
return "", "", fmt.Errorf("failed to get env credentials from azure: %w", err)
176179
}
177180
os.Unsetenv(clientIdEnv)
178181
os.Unsetenv(clientSecretKeyEnv)
@@ -185,7 +188,7 @@ func getAuth(clientId, clientSecret, clientCert, tenantId, subscriptionId, regis
185188
}
186189
aadToken, err := env.GetToken(context.Background(), policy)
187190
if err != nil {
188-
return "", "", errors.Wrap(err, "failed to fetch access token")
191+
return "", "", fmt.Errorf("failed to fetch access token: %w", err)
189192
}
190193

191194
// Get public URL for artifacts
@@ -198,7 +201,7 @@ func getAuth(clientId, clientSecret, clientCert, tenantId, subscriptionId, regis
198201
// Fetch token
199202
ACRToken, err := fetchACRToken(tenantId, aadToken.Token, registry)
200203
if err != nil {
201-
return "", "", errors.Wrap(err, "failed to fetch ACR token")
204+
return "", "", fmt.Errorf("failed to fetch ACR token: %w", err)
202205
}
203206
return ACRToken, publicUrl, nil
204207
}
@@ -213,34 +216,34 @@ func fetchACRToken(tenantId, token, registry string) (string, error) {
213216
}
214217
jsonResponse, err := http.PostForm(fmt.Sprintf("https://%s/oauth2/exchange", registry), formData)
215218
if err != nil || jsonResponse == nil {
216-
return "", errors.Wrap(err, "failed to fetch ACR token")
219+
return "", fmt.Errorf("failed to fetch ACR token: %w", err)
217220
}
218221

219222
// fetch token from response
220223
var response map[string]interface{}
221224
err = json.NewDecoder(jsonResponse.Body).Decode(&response)
222225
if err != nil {
223-
return "", errors.Wrap(err, "failed to decode oauth exchange response")
226+
return "", fmt.Errorf("failed to decode oauth exchange response: %w", err)
224227
}
225228

226229
// Parse the refresh_token from the response
227230
if t, found := response["refresh_token"]; found {
228231
if refreshToken, ok := t.(string); ok {
229232
return refreshToken, nil
230233
}
231-
return "", errors.New("failed to cast refresh token from acr")
234+
return "", fmt.Errorf("failed to cast refresh token from acr")
232235
}
233-
return "", errors.Wrap(err, "refresh token not found in response of oauth exchange call")
236+
return "", fmt.Errorf("refresh token not found in response of oauth exchange call: %w", err)
234237
}
235238

236239
func setupACRCert(cert, certPath string) error {
237240
decoded, err := base64.StdEncoding.DecodeString(cert)
238241
if err != nil {
239-
return errors.Wrap(err, "failed to base64 decode ACR certificate")
242+
return fmt.Errorf("failed to base64 decode ACR certificate: %w", err)
240243
}
241244
err = ioutil.WriteFile(certPath, decoded, 0644)
242245
if err != nil {
243-
return errors.Wrap(err, "failed to write ACR certificate")
246+
return fmt.Errorf("failed to write ACR certificate: %w", err)
244247
}
245248
return nil
246249
}
@@ -262,24 +265,24 @@ func getPublicUrl(token, registryUrl, subscriptionId string) (string, error) {
262265
req, err := http.NewRequest("GET", url, nil)
263266
if err != nil {
264267
fmt.Println(err)
265-
return "", errors.Wrap(err, "failed to create request for getting container registry setting")
268+
return "", fmt.Errorf("failed to create request for getting container registry setting: %w", err)
266269
}
267270

268271
req.Header.Add("Authorization", "Bearer "+token)
269272
res, err := client.Do(req)
270273
if err != nil {
271274
fmt.Println(err)
272-
return "", errors.Wrap(err, "failed to send request for getting container registry setting")
275+
return "", fmt.Errorf("failed to send request for getting container registry setting: %w", err)
273276
}
274277
defer res.Body.Close()
275278

276279
var response subscriptionUrlResponse
277280
err = json.NewDecoder(res.Body).Decode(&response)
278281
if err != nil {
279-
return "", errors.Wrap(err, "failed to send request for getting container registry setting")
282+
return "", fmt.Errorf("failed to send request for getting container registry setting: %w", err)
280283
}
281284
if len(response.Value) == 0 {
282-
return "", errors.New("no id present for base url")
285+
return "", fmt.Errorf("no id present for base url")
283286
}
284287
return basePublicUrl + encodeParam(response.Value[0].ID), nil
285288
}

cmd/drone-docker/main.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package main
22

33
import (
4+
"log/slog"
45
"os"
56
"runtime"
67
"strings"
78

89
"github.com/dchest/uniuri"
910
"github.com/joho/godotenv"
10-
"github.com/sirupsen/logrus"
1111
"github.com/urfave/cli"
1212

1313
docker "github.com/drone-plugins/drone-docker"
@@ -358,7 +358,8 @@ func main() {
358358
}
359359

360360
if err := app.Run(os.Args); err != nil {
361-
logrus.Fatal(err)
361+
slog.Error("application error", "error", err)
362+
os.Exit(1)
362363
}
363364
}
364365

@@ -448,16 +449,16 @@ func run(c *cli.Context) error {
448449
tag, err := docker.DefaultTagSuffix(
449450
c.String("commit.ref"),
450451
c.String("tags.suffix"),
451-
)
452-
if err != nil {
453-
logrus.Printf("cannot build docker image for %s, invalid semantic version", c.String("commit.ref"))
454-
return err
455-
}
456-
plugin.Build.Tags = tag
457-
} else {
458-
logrus.Printf("skipping automated docker build for %s", c.String("commit.ref"))
459-
return nil
452+
)
453+
if err != nil {
454+
slog.Error("cannot build docker image, invalid semantic version", "commit_ref", c.String("commit.ref"), "error", err)
455+
return err
460456
}
457+
plugin.Build.Tags = tag
458+
} else {
459+
slog.Info("skipping automated docker build", "commit_ref", c.String("commit.ref"))
460+
return nil
461+
}
461462
}
462463

463464
return plugin.Exec()

cmd/drone-ecr/main.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"log"
9+
"log/slog"
910
"os"
1011
"os/exec"
1112
"strconv"
@@ -18,7 +19,6 @@ import (
1819
ecrtypes "github.com/aws/aws-sdk-go-v2/service/ecr/types"
1920
"github.com/aws/aws-sdk-go-v2/service/sts"
2021
"github.com/joho/godotenv"
21-
"github.com/sirupsen/logrus"
2222

2323
docker "github.com/drone-plugins/drone-docker"
2424
)
@@ -130,24 +130,26 @@ func main() {
130130
}
131131
}
132132

133-
repositoryName := trimHostname(repo, registry)
134-
for _, t := range tags {
135-
exists, err := tagExists(ctx, svc, repositoryName, t)
136-
if err != nil {
137-
logrus.Fatalf("Error checking if image exists for tag %s: %v", t, err)
138-
}
139-
if exists {
140-
logrus.Infof("%s:%s: Image tag exists. Skipping push.", repo, t)
141-
os.Exit(0)
142-
}
133+
repositoryName := trimHostname(repo, registry)
134+
for _, t := range tags {
135+
exists, err := tagExists(ctx, svc, repositoryName, t)
136+
if err != nil {
137+
slog.Error("error checking if image exists for tag", "tag", t, "error", err)
138+
os.Exit(1)
143139
}
140+
if exists {
141+
slog.Info("image tag exists, skipping push", "repo", repo, "tag", t)
142+
os.Exit(0)
143+
}
144+
}
144145
}
145146

146147
cmd := exec.Command(docker.GetDroneDockerExecCmd())
147148
cmd.Stdout = os.Stdout
148149
cmd.Stderr = os.Stderr
149150
if err = cmd.Run(); err != nil {
150-
logrus.Fatal(err)
151+
slog.Error("command execution failed", "error", err)
152+
os.Exit(1)
151153
}
152154
}
153155

cmd/drone-gar/main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/base64"
66
"fmt"
77
"log"
8+
"log/slog"
89
"os"
910
"os/exec"
1011
"path"
@@ -15,7 +16,6 @@ import (
1516
"github.com/drone-plugins/drone-docker/internal/gcp"
1617

1718
"github.com/joho/godotenv"
18-
"github.com/sirupsen/logrus"
1919
"golang.org/x/oauth2"
2020
"golang.org/x/oauth2/google"
2121
)
@@ -58,11 +58,13 @@ func loadConfig() Config {
5858
if idToken != "" && projectId != "" && poolId != "" && providerId != "" && serviceAccountEmail != "" {
5959
federalToken, err := gcp.GetFederalToken(idToken, projectId, poolId, providerId)
6060
if err != nil {
61-
logrus.Fatalf("Error (getFederalToken): %s", err)
61+
slog.Error("getFederalToken error", "error", err)
62+
os.Exit(1)
6263
}
6364
accessToken, err := gcp.GetGoogleCloudAccessToken(federalToken, serviceAccountEmail)
6465
if err != nil {
65-
logrus.Fatalf("Error (getGoogleCloudAccessToken): %s", err)
66+
slog.Error("getGoogleCloudAccessToken error", "error", err)
67+
os.Exit(1)
6668
}
6769
config.AccessToken = accessToken
6870
} else {
@@ -110,7 +112,8 @@ func main() {
110112
cmd.Stderr = os.Stderr
111113
err := cmd.Run()
112114
if err != nil {
113-
logrus.Fatal(err)
115+
slog.Error("command execution failed", "error", err)
116+
os.Exit(1)
114117
}
115118
}
116119

0 commit comments

Comments
 (0)