mirror of
https://github.com/drone-plugins/drone-download.git
synced 2026-06-04 18:24:21 +08:00
Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 036a83f633 | |||
| b04de205cc | |||
| 1c2f308542 | |||
| 6b60b2c813 | |||
| 729d073d21 | |||
| 88cb1a91eb | |||
| ff9daa10fb | |||
| 3fa8e29ebb | |||
| 0163cc8e5f | |||
| 32b4cf0694 | |||
| 04fa434e66 | |||
| 7444b5dfcc | |||
| ea30096c82 | |||
| 232a8f9f81 | |||
| 7889c97a14 | |||
| af602cee0c | |||
| abef61e5f9 | |||
| 7b56372dd0 | |||
| 33539b842a | |||
| 0abfc112fc | |||
| af9152a1ee | |||
| 58abec89d2 | |||
| 1c8c6a8550 | |||
| 6b9d1bf911 | |||
| 9a456fee2a | |||
| fc84f968c5 | |||
| 495f9c89b2 | |||
| 47f5dab31b | |||
| 0081187385 | |||
| 3f15869f0e | |||
| 2595611d8a | |||
| 6c915125d8 | |||
| 9e8a758dfd | |||
| f473b82aae | |||
| e734798cd2 | |||
| 7f3900db1f | |||
| d5ac59f17d | |||
| e4d601776d | |||
| a6eb7738cd | |||
| 58321691a7 | |||
| e6aebc441a | |||
| 96e7827129 | |||
| 4e42d9104f | |||
| ceb5bdf0fe |
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
+238
-132
@@ -1,149 +1,255 @@
|
||||
workspace:
|
||||
base: /go
|
||||
path: src/github.com/drone-plugins/drone-download
|
||||
kind: pipeline
|
||||
type: vm
|
||||
name: testing
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
pool:
|
||||
use: ubuntu
|
||||
|
||||
pipeline:
|
||||
deps:
|
||||
image: golang:1.10
|
||||
pull: true
|
||||
commands:
|
||||
- go get -u github.com/golang/dep/cmd/dep
|
||||
- dep ensure
|
||||
- dep status
|
||||
steps:
|
||||
- name: lint
|
||||
image: golang:1.20
|
||||
pull: always
|
||||
commands:
|
||||
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
- golangci-lint version
|
||||
- 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
|
||||
pull: true
|
||||
commands:
|
||||
- go vet ./...
|
||||
- go test -cover ./...
|
||||
---
|
||||
kind: pipeline
|
||||
type: vm
|
||||
name: linux-amd64
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
pool:
|
||||
use: ubuntu
|
||||
|
||||
build_linux_amd64:
|
||||
image: golang:1.10
|
||||
pull: true
|
||||
group: build
|
||||
environment:
|
||||
- GOOS=linux
|
||||
- GOARCH=amd64
|
||||
- CGO_ENABLED=0
|
||||
commands:
|
||||
- |
|
||||
if test "${DRONE_TAG}" = ""; then
|
||||
go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/amd64/drone-download
|
||||
else
|
||||
go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/amd64/drone-download
|
||||
fi
|
||||
|
||||
build_linux_i386:
|
||||
image: golang:1.10
|
||||
pull: true
|
||||
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
|
||||
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/linux/amd64/drone-download .
|
||||
- name: docker
|
||||
image: plugins/docker
|
||||
settings:
|
||||
dockerfile: docker/Dockerfile.linux.amd64
|
||||
repo: plugins/download
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-amd64
|
||||
dockerfile: Dockerfile
|
||||
when:
|
||||
event: [ push, tag ]
|
||||
depends_on:
|
||||
- testing
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/**
|
||||
- refs/pull/**
|
||||
|
||||
publish_linux_i386:
|
||||
image: plugins/docker:17.12
|
||||
pull: true
|
||||
secrets: [ docker_username, docker_password ]
|
||||
group: docker
|
||||
repo: plugins/download
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-i386
|
||||
dockerfile: Dockerfile.i386
|
||||
when:
|
||||
event: [ push, tag ]
|
||||
---
|
||||
kind: pipeline
|
||||
type: vm
|
||||
name: linux-arm64
|
||||
platform:
|
||||
os: linux
|
||||
arch: arm64
|
||||
pool:
|
||||
use: ubuntu_arm64
|
||||
|
||||
publish_linux_arm64:
|
||||
image: plugins/docker:17.12
|
||||
pull: true
|
||||
secrets: [ docker_username, docker_password ]
|
||||
group: docker
|
||||
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/linux/arm64/drone-download .
|
||||
- name: docker
|
||||
image: plugins/docker
|
||||
settings:
|
||||
dockerfile: docker/Dockerfile.linux.arm64
|
||||
repo: plugins/download
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-arm64
|
||||
dockerfile: Dockerfile.arm64
|
||||
when:
|
||||
event: [ push, tag ]
|
||||
depends_on:
|
||||
- testing
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/**
|
||||
- refs/pull/**
|
||||
|
||||
publish_linux_arm:
|
||||
image: plugins/docker:17.12
|
||||
pull: true
|
||||
secrets: [ docker_username, docker_password ]
|
||||
group: docker
|
||||
---
|
||||
kind: pipeline
|
||||
type: vm
|
||||
name: windows-1809
|
||||
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
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-arm
|
||||
dockerfile: Dockerfile.arm
|
||||
when:
|
||||
event: [ push, tag ]
|
||||
auto_tag_suffix: windows-1809-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/**
|
||||
|
||||
manifests:
|
||||
image: plugins/manifest:1
|
||||
pull: true
|
||||
secrets: [ docker_username, docker_password ]
|
||||
spec: manifest.tmpl
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: vm
|
||||
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_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
|
||||
when:
|
||||
event: [ push, tag ]
|
||||
|
||||
microbadger:
|
||||
image: plugins/webhook:1
|
||||
pull: true
|
||||
secrets: [ webhook_url ]
|
||||
when:
|
||||
status: [ success ]
|
||||
depends_on:
|
||||
- linux-amd64
|
||||
- linux-arm64
|
||||
- windows-1809
|
||||
- windows-ltsc2022
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/**
|
||||
|
||||
@@ -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/
|
||||
|
||||
-->
|
||||
|
||||
@@ -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
@@ -1,30 +1,3 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.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/
|
||||
|
||||
/release/
|
||||
/drone-download*
|
||||
coverage.out
|
||||
drone-download
|
||||
|
||||
@@ -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"]
|
||||
@@ -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"]
|
||||
@@ -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
@@ -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
@@ -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
|
||||
@@ -199,4 +199,3 @@
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
@@ -1,34 +1,42 @@
|
||||
# drone-download
|
||||
|
||||
[](http://beta.drone.io/drone-plugins/drone-download)
|
||||
[](http://cloud.drone.io/drone-plugins/drone-download)
|
||||
[](https://gitter.im/drone/drone)
|
||||
[](https://discourse.drone.io)
|
||||
[](https://stackoverflow.com/questions/tagged/drone.io)
|
||||
[](https://microbadger.com/images/plugins/download "Get your own image badge on microbadger.com")
|
||||
[](http://godoc.org/github.com/drone-plugins/drone-download)
|
||||
[](https://goreportcard.com/report/github.com/drone-plugins/drone-download)
|
||||
[](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/).
|
||||
|
||||
## Build
|
||||
|
||||
Build the binary with the following commands:
|
||||
Build the binary with the following command:
|
||||
|
||||
```
|
||||
go build
|
||||
```bash
|
||||
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
|
||||
|
||||
Build the Docker image with the following commands:
|
||||
Build the Docker image with the following command:
|
||||
|
||||
```
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/amd64/drone-download
|
||||
docker build --rm -t plugins/download .
|
||||
```bash
|
||||
docker build \
|
||||
--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 \
|
||||
-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 \
|
||||
|
||||
@@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
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"
|
||||
|
||||
ADD release/linux/arm64/drone-download /bin/
|
||||
ENTRYPOINT ["/bin/drone-download"]
|
||||
ENTRYPOINT [ "/bin/drone-download" ]
|
||||
@@ -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" ]
|
||||
@@ -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" ]
|
||||
@@ -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
|
||||
@@ -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
|
||||
)
|
||||
@@ -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=
|
||||
@@ -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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/drone-plugins/drone-download/plugin"
|
||||
"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 (
|
||||
version = "0.0.0"
|
||||
build = "0"
|
||||
)
|
||||
var version = "unknown"
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "download plugin"
|
||||
app.Usage = "download plugin"
|
||||
app.Action = run
|
||||
app.Version = fmt.Sprintf("%s+%s", version, build)
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "source",
|
||||
Usage: "source url for the download",
|
||||
EnvVar: "PLUGIN_SOURCE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
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",
|
||||
},
|
||||
settings := &plugin.Settings{}
|
||||
|
||||
if _, err := os.Stat("/run/drone/env"); err == nil {
|
||||
_ = godotenv.Overload("/run/drone/env")
|
||||
}
|
||||
|
||||
app := &cli.App{
|
||||
Name: "drone-download",
|
||||
Usage: "download a file",
|
||||
Version: version,
|
||||
Flags: append(settingsFlags(settings), urfave.Flags()...),
|
||||
Action: run(settings),
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
errors.HandleExit(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run(c *cli.Context) error {
|
||||
plugin := Plugin{
|
||||
Config: Config{
|
||||
Source: c.String("source"),
|
||||
Destination: c.String("destination"),
|
||||
Authorization: c.String("authorization"),
|
||||
Username: c.String("username"),
|
||||
Password: c.String("password"),
|
||||
SkipVerify: c.Bool("skip-verify"),
|
||||
MD5: c.String("md5-checksum"),
|
||||
SHA256: c.String("sha256-checksum"),
|
||||
func run(settings *plugin.Settings) cli.ActionFunc {
|
||||
return func(ctx *cli.Context) error {
|
||||
urfave.LoggingFromContext(ctx)
|
||||
|
||||
plugin := plugin.New(
|
||||
*settings,
|
||||
urfave.PipelineFromContext(ctx),
|
||||
urfave.NetworkFromContext(ctx),
|
||||
)
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -1,151 +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()
|
||||
|
||||
_, err = io.Copy(target, resp.Body)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "copying destination failed")
|
||||
}
|
||||
|
||||
if p.Config.MD5 != "" {
|
||||
h := md5.New()
|
||||
target.Seek(0, 0)
|
||||
|
||||
if _, err := io.Copy(h, target); err != nil {
|
||||
defer os.Remove(target.Name())
|
||||
return errors.Wrap(err, "failed to compare checksum")
|
||||
}
|
||||
|
||||
check := fmt.Sprintf("%x", h.Sum(nil))
|
||||
|
||||
if p.Config.MD5 != check {
|
||||
defer os.Remove(target.Name())
|
||||
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, p.Config.MD5)
|
||||
}
|
||||
}
|
||||
|
||||
if p.Config.SHA256 != "" {
|
||||
h := sha256.New()
|
||||
target.Seek(0, 0)
|
||||
|
||||
if _, err := io.Copy(h, target); err != nil {
|
||||
defer os.Remove(target.Name())
|
||||
return errors.Wrap(err, "failed to compare checksum")
|
||||
}
|
||||
|
||||
check := fmt.Sprintf("%x", h.Sum(nil))
|
||||
|
||||
if p.Config.SHA256 != check {
|
||||
defer os.Remove(target.Name())
|
||||
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, p.Config.SHA256)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+157
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user