Compare commits

..

46 Commits

Author SHA1 Message Date
TP Honey 036a83f633 Merge pull request #40 from tphoney/use_correct_arm_runner
(fix) use correct arm runner
2023-09-15 16:00:37 +01:00
dependabot-ci b04de205cc (fix) use correct arm runner 2023-09-15 15:30:30 +01:00
TP Honey 1c2f308542 Merge pull request #34 from tphoney/build_cleanup
(maint) cleaning build up with move to harness
2022-12-07 12:08:43 +00:00
TP Honey 6b60b2c813 (maint) cleaning build up with move to harness 2022-12-07 11:52:37 +00:00
TP Honey 729d073d21 Create .drone.yml 2022-12-07 11:38:12 +00:00
TP Honey 88cb1a91eb Update README.md 2022-12-07 11:36:00 +00:00
TP Honey ff9daa10fb Merge pull request #33 from tphoney/harness_move
(maint) move to harness.drone.io
2022-12-07 11:22:06 +00:00
TP Honey 3fa8e29ebb (maint) move to harness.drone.io 2022-12-07 11:16:56 +00:00
TP Honey 0163cc8e5f remove microbadger 2022-08-02 12:38:34 +01:00
TP Honey 32b4cf0694 Merge pull request #30 from tphoney/update_go
(maint) update go to 1.18 and deps
2022-08-02 12:31:12 +01:00
TP Honey 04fa434e66 (maint) update go to 1.18 and deps 2022-08-02 12:28:43 +01:00
TP Honey 7444b5dfcc Merge pull request #24 from drone-plugins/renovate/github.com-joho-godotenv-1.x
Update module github.com/joho/godotenv to v1.4.0
2022-07-05 11:21:10 +01:00
Renovate Bot ea30096c82 Update module github.com/joho/godotenv to v1.4.0 2021-10-20 06:25:55 +00:00
Don 232a8f9f81 Merge pull request #18 from drone-plugins/boilr-update
Update to latest boilr template
2020-09-17 07:28:44 -07:00
Don 7889c97a14 Update to latest boilr template 2020-09-14 20:48:23 -07:00
Don af602cee0c Merge pull request #17 from drone-plugins/plugin-lib
Update to use drone-plugin-lib
2020-07-03 09:04:00 -07:00
Don abef61e5f9 Add additional logging 2020-06-17 09:18:55 -07:00
Don 7b56372dd0 Use the drone plugin lib 2020-06-16 22:30:09 -07:00
Thomas Boerger 33539b842a Merge pull request #15 from drone-plugins/improve-config
Drop renovate, proper version definition, unified jsonnet config
2019-09-17 21:41:23 +02:00
Thomas Boerger 0abfc112fc Fix microbadger settings and enable auto_tag for manifest 2019-03-31 23:50:24 +02:00
Thomas Boerger af9152a1ee Fix manifest template helper 2019-03-31 23:50:24 +02:00
Thomas Boerger 58abec89d2 Drop import of unused fmt package 2019-03-31 23:50:24 +02:00
Thomas Boerger 1c8c6a8550 Replace godep with gomod 2019-03-31 23:50:23 +02:00
Thomas Boerger 6b9d1bf911 Unified documentation and readme 2019-03-31 23:50:23 +02:00
Thomas Boerger 9a456fee2a Add a reliable version and integrate libsonnet definition 2019-03-31 23:50:23 +02:00
Thomas Boerger fc84f968c5 Drop renovate config, it is simply too noisy 2019-03-31 23:50:23 +02:00
Thomas Boerger 495f9c89b2 Merge pull request #16 from joyqat/master
WIP: impl #14
2019-02-20 13:42:48 +01:00
joyqat 47f5dab31b clearify error info 2019-02-20 15:54:31 +08:00
joyqat 0081187385 remove redundant code 2019-02-20 09:37:02 +08:00
joyqat 3f15869f0e use filepath instead of path to work on all platform 2019-02-20 09:23:31 +08:00
joyqat 2595611d8a impl #14 2019-02-17 17:42:20 +08:00
Thomas Boerger 6c915125d8 Merge pull request #13 from drone-plugins/upgrade-drone
Upgrade and switch to Drone 1.0.0
2019-01-23 11:03:05 +01:00
Thomas Boerger 9e8a758dfd Execute built binary as simple test 2019-01-22 23:13:02 +01:00
Thomas Boerger f473b82aae Add some basic issue template content 2019-01-21 21:02:11 +01:00
Thomas Boerger e734798cd2 Add probot settings config 2019-01-21 20:58:25 +01:00
Thomas Boerger 7f3900db1f Remove duplicated badge 2019-01-21 09:32:36 +01:00
Thomas Boerger d5ac59f17d Fix duplicated step names 2019-01-21 01:13:49 +01:00
Thomas Boerger e4d601776d Update badges within readme 2019-01-21 00:19:18 +01:00
Thomas Boerger a6eb7738cd Migrate configs to drone 1.0.0 and drop appveyor 2019-01-20 23:52:02 +01:00
Thomas Boerger 58321691a7 Add manifest template to docker folder 2019-01-20 22:21:27 +01:00
Thomas Boerger e6aebc441a Move dockerfiles to docker folder 2019-01-20 22:20:05 +01:00
Thomas Boerger 96e7827129 Merge pull request #12 from drone-plugins/renovate/configure
Configure Renovate
2019-01-19 21:32:20 +01:00
Thomas Boerger 4e42d9104f Update renovate.json 2019-01-19 12:01:53 +01:00
Renovate Bot ceb5bdf0fe Add renovate.json 2019-01-19 02:54:52 +00:00
Thomas Boerger f06bb4fcc7 Merge pull request #11 from drone-plugins/checksum-fix
Copy the target file first and fix checksum checks
2018-09-27 20:29:14 +02:00
Thomas Boerger 852b0b104c Copy the target file first and fix checksum checks 2018-09-27 14:37:43 +02:00
28 changed files with 801 additions and 565 deletions
-68
View File
@@ -1,68 +0,0 @@
version: '{build}'
image: 'Visual Studio 2017'
platform: 'x64'
clone_folder: 'c:\gopath\src\github.com\drone-plugins\drone-download'
max_jobs: 1
environment:
GOPATH: c:\gopath
DOCKER_USERNAME:
secure: '4YzzahbEiMZQJpOCOd1LAw=='
DOCKER_PASSWORD:
secure: 'VqO/G3Zfslu6zSLdwHKO+Q=='
install:
- ps: |
docker version
go version
- ps: |
$env:Path = "c:\gopath\bin;$env:Path"
build_script:
- ps: |
go get -u github.com/golang/dep/cmd/dep
dep ensure
if ( $env:APPVEYOR_REPO_TAG -eq 'false' ) {
go build -ldflags "-X main.build=$env:APPVEYOR_BUILD_VERSION" -a -o release/drone-download.exe
} else {
$version = $env:APPVEYOR_REPO_TAG_NAME.substring(1)
go build -ldflags "-X main.version=$version -X main.build=$env:APPVEYOR_BUILD_VERSION" -a -o release/drone-download.exe
}
docker pull microsoft/nanoserver:10.0.14393.1593
docker build -f Dockerfile.windows -t plugins/download:windows-amd64 .
test_script:
- ps: |
docker run --rm plugins/download:windows-amd64 --version
deploy_script:
- ps: |
$ErrorActionPreference = 'Stop';
if ( $env:APPVEYOR_PULL_REQUEST_NUMBER ) {
Write-Host Nothing to deploy.
} else {
echo $env:DOCKER_PASSWORD | docker login --username $env:DOCKER_USERNAME --password-stdin
if ( $env:APPVEYOR_REPO_TAG -eq 'true' ) {
$major,$minor,$patch = $env:APPVEYOR_REPO_TAG_NAME.substring(1).split('.')
docker push plugins/download:windows-amd64
docker tag plugins/download:windows-amd64 plugins/download:$major.$minor.$patch-windows-amd64
docker push plugins/download:$major.$minor.$patch-windows-amd64
docker tag plugins/download:windows-amd64 plugins/download:$major.$minor-windows-amd64
docker push plugins/download:$major.$minor-windows-amd64
docker tag plugins/download:windows-amd64 plugins/download:$major-windows-amd64
docker push plugins/download:$major-windows-amd64
} else {
if ( $env:APPVEYOR_REPO_BRANCH -eq 'master' ) {
docker push plugins/download:windows-amd64
}
}
}
View File
+238 -132
View File
@@ -1,149 +1,255 @@
workspace: kind: pipeline
base: /go type: vm
path: src/github.com/drone-plugins/drone-download name: testing
platform:
os: linux
arch: amd64
pool:
use: ubuntu
pipeline: steps:
deps: - name: lint
image: golang:1.10 image: golang:1.20
pull: true pull: always
commands: commands:
- go get -u github.com/golang/dep/cmd/dep - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- dep ensure - golangci-lint version
- dep status - golangci-lint run
volumes:
- name: gopath
path: "/go"
- name: test
image: golang:1.20
commands:
- go test -cover ./...
volumes:
- name: gopath
path: "/go"
volumes:
- name: gopath
temp: {}
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
test: ---
image: golang:1.10 kind: pipeline
pull: true type: vm
commands: name: linux-amd64
- go vet ./... platform:
- go test -cover ./... os: linux
arch: amd64
pool:
use: ubuntu
build_linux_amd64: steps:
image: golang:1.10 - name: environment
pull: true image: golang:1.20
group: build pull: always
environment: environment:
- GOOS=linux CGO_ENABLED: '0'
- GOARCH=amd64 commands:
- CGO_ENABLED=0 - go version
commands: - go env
- | - name: build
if test "${DRONE_TAG}" = ""; then image: golang:1.20
go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/amd64/drone-download environment:
else CGO_ENABLED: '0'
go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/amd64/drone-download commands:
fi - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/amd64/drone-download .
- name: docker
build_linux_i386: image: plugins/docker
image: golang:1.10 settings:
pull: true dockerfile: docker/Dockerfile.linux.amd64
group: build
environment:
- GOOS=linux
- GOARCH=386
- CGO_ENABLED=0
commands:
- |
if test "${DRONE_TAG}" = ""; then
go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/i386/drone-download
else
go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/i386/drone-download
fi
build_linux_arm64:
image: golang:1.10
pull: true
group: build
environment:
- GOOS=linux
- GOARCH=arm64
- CGO_ENABLED=0
commands:
- |
if test "${DRONE_TAG}" = ""; then
go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm64/drone-download
else
go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm64/drone-download
fi
build_linux_arm:
image: golang:1.10
pull: true
group: build
environment:
- GOOS=linux
- GOARCH=arm
- CGO_ENABLED=0
- GOARM=7
commands:
- |
if test "${DRONE_TAG}" = ""; then
go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm/drone-download
else
go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm/drone-download
fi
publish_linux_amd64:
image: plugins/docker:17.12
pull: true
secrets: [ docker_username, docker_password ]
group: docker
repo: plugins/download repo: plugins/download
username:
from_secret: docker_username
password:
from_secret: docker_password
auto_tag: true auto_tag: true
auto_tag_suffix: linux-amd64 auto_tag_suffix: linux-amd64
dockerfile: Dockerfile depends_on:
when: - testing
event: [ push, tag ] trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
publish_linux_i386: ---
image: plugins/docker:17.12 kind: pipeline
pull: true type: vm
secrets: [ docker_username, docker_password ] name: linux-arm64
group: docker platform:
repo: plugins/download os: linux
auto_tag: true arch: arm64
auto_tag_suffix: linux-i386 pool:
dockerfile: Dockerfile.i386 use: ubuntu_arm64
when:
event: [ push, tag ]
publish_linux_arm64: steps:
image: plugins/docker:17.12 - name: environment
pull: true image: golang:1.20
secrets: [ docker_username, docker_password ] pull: always
group: docker environment:
CGO_ENABLED: '0'
commands:
- go version
- go env
- name: build
image: golang:1.20
environment:
CGO_ENABLED: '0'
commands:
- go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/arm64/drone-download .
- name: docker
image: plugins/docker
settings:
dockerfile: docker/Dockerfile.linux.arm64
repo: plugins/download repo: plugins/download
username:
from_secret: docker_username
password:
from_secret: docker_password
auto_tag: true auto_tag: true
auto_tag_suffix: linux-arm64 auto_tag_suffix: linux-arm64
dockerfile: Dockerfile.arm64 depends_on:
when: - testing
event: [ push, tag ] trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
publish_linux_arm: ---
image: plugins/docker:17.12 kind: pipeline
pull: true type: vm
secrets: [ docker_username, docker_password ] name: windows-1809
group: docker platform:
os: windows
arch: amd64
pool:
use: windows
steps:
- name: environment
image: golang:1.20
pull: always
environment:
CGO_ENABLED: '0'
commands:
- go version
- go env
- name: build
image: golang:1.20
environment:
CGO_ENABLED: '0'
commands:
- go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-download.exe .
- name: docker
image: plugins/docker
settings:
dockerfile: docker/Dockerfile.windows.1809
repo: plugins/download repo: plugins/download
username:
from_secret: docker_username
password:
from_secret: docker_password
auto_tag: true auto_tag: true
auto_tag_suffix: linux-arm auto_tag_suffix: windows-1809-amd64
dockerfile: Dockerfile.arm daemon_off: true
when: purge: false
event: [ push, tag ] when:
ref:
- refs/heads/master
- refs/tags/**
depends_on:
- testing
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
manifests:
image: plugins/manifest:1 ---
pull: true kind: pipeline
secrets: [ docker_username, docker_password ] type: vm
spec: manifest.tmpl name: windows-ltsc2022
platform:
os: windows
arch: amd64
pool:
use: windows-2022
steps:
- name: environment
image: golang:1.20
pull: always
environment:
CGO_ENABLED: '0'
commands:
- go version
- go env
- name: build
image: golang:1.20
environment:
CGO_ENABLED: '0'
commands:
- go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-download.exe .
- name: docker
image: plugins/docker
settings:
dockerfile: docker/Dockerfile.windows.ltsc2022
repo: plugins/download
username:
from_secret: docker_username
password:
from_secret: docker_password
auto_tag: true auto_tag: true
auto_tag_suffix: windows-ltsc2022-amd64
daemon_off: true
purge: false
when:
ref:
- refs/heads/master
- refs/tags/**
depends_on:
- testing
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
---
kind: pipeline
type: vm
name: manifest
platform:
os: linux
arch: amd64
pool:
use: ubuntu
steps:
- name: manifest
image: plugins/manifest
settings:
auto_tag: 'true'
username:
from_secret: docker_username
password:
from_secret: docker_password
spec: docker/manifest.tmpl
ignore_missing: true ignore_missing: true
when: depends_on:
event: [ push, tag ] - linux-amd64
- linux-arm64
microbadger: - windows-1809
image: plugins/webhook:1 - windows-ltsc2022
pull: true trigger:
secrets: [ webhook_url ] ref:
when: - refs/heads/master
status: [ success ] - refs/tags/**
+9
View File
@@ -0,0 +1,9 @@
<!-- PLEASE READ BEFORE DELETING
Bugs or Issues? Due to the high number of false positive issues we receive,
please do not create a GitHub issue until you have discussed and verified
with community support at:
https://discourse.drone.io/
-->
+77
View File
@@ -0,0 +1,77 @@
repository:
name: drone-download
description: Drone plugin for downloading files
homepage: http://plugins.drone.io/drone-plugins/drone-download
topics: drone, drone-plugin
private: false
has_issues: true
has_wiki: false
has_downloads: false
default_branch: master
allow_squash_merge: true
allow_merge_commit: true
allow_rebase_merge: true
labels:
- name: bug
color: d73a4a
description: Something isn't working
- name: duplicate
color: cfd3d7
description: This issue or pull request already exists
- name: enhancement
color: a2eeef
description: New feature or request
- name: good first issue
color: 7057ff
description: Good for newcomers
- name: help wanted
color: 008672
description: Extra attention is needed
- name: invalid
color: e4e669
description: This doesn't seem right
- name: question
color: d876e3
description: Further information is requested
- name: renovate
color: e99695
description: Automated action from Renovate
- name: wontfix
color: ffffff
description: This will not be worked on
teams:
- name: Admins
permission: admin
- name: Captain
permission: admin
- name: Maintainers
permission: push
branches:
- name: master
protection:
required_pull_request_reviews:
required_approving_review_count: 1
dismiss_stale_reviews: false
require_code_owner_reviews: false
dismissal_restrictions:
teams:
- Admins
- Captain
required_status_checks:
strict: true
contexts:
- continuous-integration/drone/pr
enforce_admins: false
restrictions:
apps:
- renovate
users: []
teams:
- Admins
- Maintainers
+2 -29
View File
@@ -1,30 +1,3 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects) /release/
*.o /drone-download*
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
release/
vendor/
coverage.out coverage.out
drone-download
-9
View File
@@ -1,9 +0,0 @@
FROM plugins/base:multiarch
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
org.label-schema.name="Drone Download" \
org.label-schema.vendor="Drone.IO Community" \
org.label-schema.schema-version="1.0"
ADD release/linux/arm/drone-download /bin/
ENTRYPOINT ["/bin/drone-download"]
-9
View File
@@ -1,9 +0,0 @@
FROM plugins/base:multiarch
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
org.label-schema.name="Drone Download" \
org.label-schema.vendor="Drone.IO Community" \
org.label-schema.schema-version="1.0"
ADD release/linux/i386/drone-download /bin/
ENTRYPOINT ["/bin/drone-download"]
-12
View File
@@ -1,12 +0,0 @@
# escape=`
FROM microsoft/nanoserver:10.0.14393.1593
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone Download" `
org.label-schema.vendor="Drone.IO Community" `
org.label-schema.schema-version="1.0"
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ADD release\drone-download.exe c:\drone-download.exe
ENTRYPOINT [ "c:\\drone-download.exe" ]
Generated
-27
View File
@@ -1,27 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
name = "github.com/jackspirou/syscerts"
packages = ["."]
revision = "b68f5469dff16e102bd6a2d5b3e79341c938d736"
[[projects]]
name = "github.com/pkg/errors"
packages = ["."]
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
version = "v0.8.0"
[[projects]]
name = "github.com/urfave/cli"
packages = ["."]
revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1"
version = "v1.20.0"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "2de092315de302f8524a364964c2188740930cca12093b5cb936c74addfdcf58"
solver-name = "gps-cdcl"
solver-version = 1
-15
View File
@@ -1,15 +0,0 @@
[[constraint]]
branch = "master"
name = "github.com/jackspirou/syscerts"
[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"
[[constraint]]
name = "github.com/urfave/cli"
version = "1.20.0"
[prune]
go-tests = true
unused-packages = true
-1
View File
@@ -199,4 +199,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
+19 -11
View File
@@ -1,34 +1,42 @@
# drone-download # drone-download
[![Build Status](http://beta.drone.io/api/badges/drone-plugins/drone-download/status.svg)](http://beta.drone.io/drone-plugins/drone-download) [![Build Status](http://cloud.drone.io/api/badges/drone-plugins/drone-download/status.svg)](http://cloud.drone.io/drone-plugins/drone-download)
[![Gitter chat](https://badges.gitter.im/drone/drone.png)](https://gitter.im/drone/drone)
[![Join the discussion at https://discourse.drone.io](https://img.shields.io/badge/discourse-forum-orange.svg)](https://discourse.drone.io) [![Join the discussion at https://discourse.drone.io](https://img.shields.io/badge/discourse-forum-orange.svg)](https://discourse.drone.io)
[![Drone questions at https://stackoverflow.com](https://img.shields.io/badge/drone-stackoverflow-orange.svg)](https://stackoverflow.com/questions/tagged/drone.io) [![Drone questions at https://stackoverflow.com](https://img.shields.io/badge/drone-stackoverflow-orange.svg)](https://stackoverflow.com/questions/tagged/drone.io)
[![](https://images.microbadger.com/badges/image/plugins/download.svg)](https://microbadger.com/images/plugins/download "Get your own image badge on microbadger.com")
[![Go Doc](https://godoc.org/github.com/drone-plugins/drone-download?status.svg)](http://godoc.org/github.com/drone-plugins/drone-download) [![Go Doc](https://godoc.org/github.com/drone-plugins/drone-download?status.svg)](http://godoc.org/github.com/drone-plugins/drone-download)
[![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-download)](https://goreportcard.com/report/github.com/drone-plugins/drone-download) [![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-download)](https://goreportcard.com/report/github.com/drone-plugins/drone-download)
[![](https://images.microbadger.com/badges/image/plugins/download.svg)](https://microbadger.com/images/plugins/download "Get your own image badge on microbadger.com")
Drone plugin to download files required for a build, also makes it possible to inject basic authentication in a secure way. For the usage information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/drone-plugins/drone-download/). Drone plugin to download files required for a build, also makes it possible to inject basic authentication in a secure way. For the usage information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/drone-plugins/drone-download/).
## Build ## Build
Build the binary with the following commands: Build the binary with the following command:
``` ```bash
go build export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on
go build -v -a -tags netgo -o release/linux/amd64/drone-download ./cmd/drone-download
``` ```
## Docker ## Docker
Build the Docker image with the following commands: Build the Docker image with the following command:
``` ```bash
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/amd64/drone-download docker build \
docker build --rm -t plugins/download . --label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
--label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \
--file docker/Dockerfile.linux.amd64 --tag plugins/download .
``` ```
### Usage ## Usage
``` ```bash
docker run --rm \ docker run --rm \
-e PLUGIN_SOURCE=https://github.com/drone/drone-cli/releases/download/v0.8.5/drone_linux_amd64.tar.gz \ -e PLUGIN_SOURCE=https://github.com/drone/drone-cli/releases/download/v0.8.5/drone_linux_amd64.tar.gz \
-e PLUGIN_DESTINATION=drone_linux.tar.gz \ -e PLUGIN_DESTINATION=drone_linux.tar.gz \
+1 -1
View File
@@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
org.label-schema.schema-version="1.0" org.label-schema.schema-version="1.0"
ADD release/linux/amd64/drone-download /bin/ ADD release/linux/amd64/drone-download /bin/
ENTRYPOINT ["/bin/drone-download"] ENTRYPOINT [ "/bin/drone-download" ]
@@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
org.label-schema.schema-version="1.0" org.label-schema.schema-version="1.0"
ADD release/linux/arm64/drone-download /bin/ ADD release/linux/arm64/drone-download /bin/
ENTRYPOINT ["/bin/drone-download"] ENTRYPOINT [ "/bin/drone-download" ]
+10
View File
@@ -0,0 +1,10 @@
# escape=`
FROM plugins/base:windows-1809-amd64@sha256:61095306fa56d51adc841f2b0f93f511efb5792d12f2549bb2eb1cbce02c1f05
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone Download" `
org.label-schema.vendor="Drone.IO Community" `
org.label-schema.schema-version="1.0"
ADD release/windows/amd64/drone-download.exe C:/bin/drone-download.exe
ENTRYPOINT [ "C:\\bin\\drone-download.exe" ]
+10
View File
@@ -0,0 +1,10 @@
# escape=`
FROM plugins/base:windows-ltsc2022-amd64@sha256:0f90d5bceb432f1ee6f93cf44eed6a38c322834edd55df8a6648c9e6f15131f4
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone Download" `
org.label-schema.vendor="Drone.IO Community" `
org.label-schema.schema-version="1.0"
ADD release/windows/amd64/drone-download.exe C:/bin/drone-download.exe
ENTRYPOINT [ "C:\\bin\\drone-download.exe" ]
+29
View File
@@ -0,0 +1,29 @@
image: plugins/download:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
- {{this}}
{{/each}}
{{/if}}
manifests:
- image: plugins/download:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
platform:
architecture: amd64
os: linux
- image: plugins/download:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
platform:
architecture: arm64
os: linux
variant: v8
- image: plugins/download:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64
platform:
architecture: amd64
os: windows
version: 1809
- image: plugins/download:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}ltsc2022-amd64
platform:
architecture: amd64
os: windows
version: 1809
+17
View File
@@ -0,0 +1,17 @@
module github.com/drone-plugins/drone-download
go 1.20
require (
github.com/drone-plugins/drone-plugin-lib v0.4.0
github.com/joho/godotenv v1.4.0
github.com/sirupsen/logrus v1.9.0
github.com/urfave/cli/v2 v2.11.1
)
require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect
)
+48
View File
@@ -0,0 +1,48 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/drone-plugins/drone-plugin-lib v0.4.0 h1:qywEYGhquUuid6zNLmKia8CWY1TUa8jPQQ/G9ozfAmc=
github.com/drone-plugins/drone-plugin-lib v0.4.0/go.mod h1:EgqogX38GoJFtckeSQyhBJYX8P+KWBPhdprAVvyRxF8=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/cli/v2 v2.11.1 h1:UKK6SP7fV3eKOefbS87iT9YHefv7iB/53ih6e+GNAsE=
github.com/urfave/cli/v2 v2.11.1/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220731174439-a90be440212d h1:Sv5ogFZatcgIMMtBSTTAgMYsicp25MXBubjXNDKwm80=
golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
+99 -72
View File
@@ -1,90 +1,117 @@
// Copyright (c) 2020, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
// DO NOT MODIFY THIS FILE DIRECTLY
package main package main
import ( import (
"fmt"
"log"
"os" "os"
"github.com/pkg/errors" "github.com/drone-plugins/drone-download/plugin"
"github.com/urfave/cli" "github.com/drone-plugins/drone-plugin-lib/errors"
"github.com/drone-plugins/drone-plugin-lib/urfave"
"github.com/joho/godotenv"
"github.com/urfave/cli/v2"
) )
var ( var version = "unknown"
version = "0.0.0"
build = "0"
)
func main() { func main() {
app := cli.NewApp() settings := &plugin.Settings{}
app.Name = "download plugin"
app.Usage = "download plugin" if _, err := os.Stat("/run/drone/env"); err == nil {
app.Action = run _ = godotenv.Overload("/run/drone/env")
app.Version = fmt.Sprintf("%s+%s", version, build) }
app.Flags = []cli.Flag{
cli.StringFlag{ app := &cli.App{
Name: "source", Name: "drone-download",
Usage: "source url for the download", Usage: "download a file",
EnvVar: "PLUGIN_SOURCE", Version: version,
}, Flags: append(settingsFlags(settings), urfave.Flags()...),
cli.StringFlag{ Action: run(settings),
Name: "destination",
Usage: "destination for the download",
EnvVar: "PLUGIN_DESTINATION",
},
cli.StringFlag{
Name: "authorization",
Usage: "value to send in the authorization header",
EnvVar: "PLUGIN_AUTHORIZATION,DOWNLOAD_AUTHORIZATION",
},
cli.StringFlag{
Name: "username",
Usage: "username for basic auth",
EnvVar: "PLUGIN_USERNAME,DOWNLOAD_USERNAME",
},
cli.StringFlag{
Name: "password",
Usage: "password for basic auth",
EnvVar: "PLUGIN_PASSWORD,DOWNLOAD_PASSWORD",
},
cli.BoolFlag{
Name: "skip-verify",
Usage: "skip ssl verification",
EnvVar: "PLUGIN_SKIP_VERIFY",
},
cli.StringFlag{
Name: "md5-checksum",
Usage: "checksum in md5 format",
EnvVar: "PLUGIN_MD5",
},
cli.StringFlag{
Name: "sha256-checksum",
Usage: "checksum in sha256 format",
EnvVar: "PLUGIN_SHA256,PLUGIN_SHA265",
},
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {
log.Fatal(err) errors.HandleExit(err)
} }
} }
func run(c *cli.Context) error { func run(settings *plugin.Settings) cli.ActionFunc {
plugin := Plugin{ return func(ctx *cli.Context) error {
Config: Config{ urfave.LoggingFromContext(ctx)
Source: c.String("source"),
Destination: c.String("destination"), plugin := plugin.New(
Authorization: c.String("authorization"), *settings,
Username: c.String("username"), urfave.PipelineFromContext(ctx),
Password: c.String("password"), urfave.NetworkFromContext(ctx),
SkipVerify: c.Bool("skip-verify"), )
MD5: c.String("md5-checksum"),
SHA256: c.String("sha256-checksum"), if err := plugin.Validate(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
}
return errors.ExitMessagef("validation failed: %w", err)
}
if err := plugin.Execute(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
}
return errors.ExitMessagef("execution failed: %w", err)
}
return nil
}
}
func settingsFlags(settings *plugin.Settings) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "source",
Usage: "source url for the download",
EnvVars: []string{"PLUGIN_SOURCE"},
Destination: &settings.Source,
},
&cli.StringFlag{
Name: "destination",
Usage: "destination for the download",
EnvVars: []string{"PLUGIN_DESTINATION"},
Destination: &settings.Destination,
},
&cli.StringFlag{
Name: "authorization",
Usage: "value to send in the authorization header",
EnvVars: []string{"PLUGIN_AUTHORIZATION", "DOWNLOAD_AUTHORIZATION"},
Destination: &settings.Authorization,
},
&cli.StringFlag{
Name: "username",
Usage: "username for basic auth",
EnvVars: []string{"PLUGIN_USERNAME", "DOWNLOAD_USERNAME"},
Destination: &settings.Username,
},
&cli.StringFlag{
Name: "password",
Usage: "password for basic auth",
EnvVars: []string{"PLUGIN_PASSWORD", "DOWNLOAD_PASSWORD"},
Destination: &settings.Password,
},
&cli.StringFlag{
Name: "md5-checksum",
Usage: "checksum in md5 format",
EnvVars: []string{"PLUGIN_MD5"},
Destination: &settings.MD5,
},
&cli.StringFlag{
Name: "sha256-checksum",
Usage: "checksum in sha256 format",
EnvVars: []string{"PLUGIN_SHA256", "PLUGIN_SHA265"},
Destination: &settings.SHA256,
}, },
} }
if plugin.Config.Source == "" {
return errors.New("Missing source URL")
}
return plugin.Exec()
} }
-33
View File
@@ -1,33 +0,0 @@
image: plugins/download:{{#if build.tag}}{{trimPrefix build.tag "v"}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
- {{this}}
{{/each}}
{{/if}}
manifests:
-
image: plugins/download:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-amd64
platform:
architecture: amd64
os: linux
-
image: plugins/download:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-i386
platform:
architecture: 386
os: linux
-
image: plugins/download:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-arm64
platform:
architecture: arm64
os: linux
-
image: plugins/download:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-arm
platform:
architecture: arm
os: linux
-
image: plugins/download:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}windows-amd64
platform:
architecture: amd64
os: windows
-145
View File
@@ -1,145 +0,0 @@
package main
import (
"crypto/md5"
"crypto/sha256"
"crypto/tls"
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
"path"
"time"
"github.com/jackspirou/syscerts"
"github.com/pkg/errors"
)
type (
Config struct {
Source string
Destination string
Authorization string
Username string
Password string
SkipVerify bool
MD5 string
SHA256 string
}
Plugin struct {
Config Config
}
)
func (p Plugin) Exec() error {
destination := p.Config.Destination
if destination == "" {
u, err := url.Parse(p.Config.Source)
if err != nil {
return errors.Wrap(err, "parsing source failed")
}
destination = path.Base(u.Path)
}
log.Printf("downloading to %s", destination)
client := &http.Client{
Timeout: time.Minute * 5,
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{
RootCAs: syscerts.SystemRootsPool(),
InsecureSkipVerify: p.Config.SkipVerify,
},
},
CheckRedirect: func(req *http.Request, via []*http.Request) error {
if p.Config.Username != "" && p.Config.Password != "" {
req.SetBasicAuth(p.Config.Username, p.Config.Password)
}
if p.Config.Authorization != "" {
req.Header.Add("Authorization", p.Config.Authorization)
}
return nil
},
}
req, err := http.NewRequest(
"GET",
p.Config.Source,
nil,
)
if err != nil {
return errors.Wrap(err, "initializing request failed")
}
if p.Config.Username != "" && p.Config.Password != "" {
req.SetBasicAuth(p.Config.Username, p.Config.Password)
}
if p.Config.Authorization != "" {
req.Header.Add("Authorization", p.Config.Authorization)
}
resp, err := client.Do(req)
if err != nil {
return errors.Wrap(err, "executing request failed")
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return errors.Errorf("request failed, status %s", http.StatusText(resp.StatusCode))
}
target, err := os.Create(destination)
if err != nil {
return errors.Wrap(err, "creating destination failed")
}
defer target.Close()
if p.Config.MD5 != "" {
h := md5.New()
if _, err := io.Copy(h, resp.Body); err != nil {
return errors.Wrap(err, "failed to compare checksum")
}
check := fmt.Sprintf("%x", h.Sum(nil))
if p.Config.MD5 != check {
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, p.Config.MD5)
}
}
if p.Config.SHA256 != "" {
h := sha256.New()
if _, err := io.Copy(h, resp.Body); err != nil {
return errors.Wrap(err, "failed to compare checksum")
}
check := fmt.Sprintf("%x", h.Sum(nil))
if p.Config.SHA256 != check {
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, p.Config.SHA256)
}
}
_, err = io.Copy(target, resp.Body)
if err != nil {
return errors.Wrap(err, "copying destination failed")
}
return nil
}
+157
View File
@@ -0,0 +1,157 @@
// Copyright (c) 2020, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import (
"crypto/md5"
"crypto/sha256"
"fmt"
"hash"
"io"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strings"
"github.com/sirupsen/logrus"
)
// Settings for the plugin.
type Settings struct {
Source string
Destination string
Authorization string
Username string
Password string
MD5 string
SHA256 string
destination string
}
// Validate handles the settings validation of the plugin.
func (p *Plugin) Validate() error {
// Verify the source url
source := p.settings.Source
if source == "" {
return fmt.Errorf("no source provided")
}
u, err := url.Parse(source)
if err != nil {
return fmt.Errorf("could not parse url %s: %w", source, err)
}
// Verify the destination
destination := filepath.ToSlash(p.settings.Destination)
if destination == "" {
destination = path.Base(u.Path)
} else if strings.HasSuffix(destination, "/") {
destination = path.Join(destination, path.Base(u.Path))
}
destination = filepath.FromSlash(path.Clean(destination))
err = os.MkdirAll(filepath.Dir(destination), os.ModePerm)
if err != nil {
return fmt.Errorf("creating directory failed: %w", err)
}
p.settings.destination = destination
return nil
}
// Execute provides the implementation of the plugin.
func (p *Plugin) Execute() error {
req, err := http.NewRequestWithContext(
p.network.Context,
"GET",
p.settings.Source,
nil,
)
if err != nil {
return fmt.Errorf("initializing request failed: %w", err)
}
p.addAuth(req)
client := p.network.Client
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
p.addAuth(req)
return nil
}
logrus.WithFields(logrus.Fields{
"source": p.settings.Source,
"destination": p.settings.destination,
}).Info("Downloading file")
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("executing request failed: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("request failed, status %s", http.StatusText(resp.StatusCode))
}
target, err := os.Create(p.settings.destination)
if err != nil {
return fmt.Errorf("creating destination failed: %w", err)
}
defer target.Close()
_, err = io.Copy(target, resp.Body)
if err != nil {
return fmt.Errorf("copying destination failed: %w", err)
}
var h hash.Hash
alg := ""
exp := ""
if p.settings.SHA256 != "" {
exp = p.settings.SHA256
alg = "SHA256"
h = sha256.New()
} else if p.settings.MD5 != "" {
exp = p.settings.MD5
alg = "MD5"
h = md5.New()
}
if exp != "" {
logrus.WithField("hash", alg).Info("Computing checksum")
_, _ = target.Seek(0, 0)
if _, err := io.Copy(h, target); err != nil {
defer os.Remove(target.Name())
return fmt.Errorf("failed to compare checksum: %w", err)
}
check := fmt.Sprintf("%x", h.Sum(nil))
if exp != check {
defer os.Remove(target.Name())
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, exp)
}
logrus.WithField("checksum", check).Info("Checksum matched")
}
return nil
}
func (p *Plugin) addAuth(req *http.Request) {
if p.settings.Username != "" && p.settings.Password != "" {
req.SetBasicAuth(p.settings.Username, p.settings.Password)
}
if p.settings.Authorization != "" {
req.Header.Add("Authorization", p.settings.Authorization)
}
}
+18
View File
@@ -0,0 +1,18 @@
// Copyright (c) 2020, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import (
"testing"
)
func TestValidate(t *testing.T) {
t.Skip()
}
func TestExecute(t *testing.T) {
t.Skip()
}
+26
View File
@@ -0,0 +1,26 @@
// Copyright (c) 2020, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import (
"github.com/drone-plugins/drone-plugin-lib/drone"
)
// Plugin implements drone.Plugin to provide the plugin implementation.
type Plugin struct {
settings Settings
pipeline drone.Pipeline
network drone.Network
}
// New initializes a plugin from the given Settings, Pipeline, and Network.
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) drone.Plugin {
return &Plugin{
settings: settings,
pipeline: pipeline,
network: network,
}
}
+14
View File
@@ -0,0 +1,14 @@
// Copyright (c) 2020, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import (
"testing"
)
func TestPlugin(t *testing.T) {
t.Skip()
}
+26
View File
@@ -0,0 +1,26 @@
{
"extends": [
"config:base",
":automergeMinor",
":automergeDigest"
],
"enabledManagers": [
"dockerfile",
"gomod"
],
"dockerfile": {
"fileMatch": [
"docker/Dockerfile\\.linux\\.(arm|arm64|amd64|multiarch)",
"docker/Dockerfile\\.windows\\.(1809|1903|1909|2004)"
],
"pinDigests": true
},
"gomod": {
"postUpdateOptions": [
"gomodTidy"
]
},
"labels": [
"renovate"
]
}