Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

ATEAM-10574 update docs for local testing #173

Merged
merged 6 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 245 additions & 0 deletions .drone-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
---

# This is an example of a Drone pipeline that can be run locally
kind: pipeline
name: local-pipeline

platform:
os: linux
arch: amd64

clone:
depth: 50

steps:
# This is needed for the tags. And the tags are needed to determine version.
- name: fetch
image: docker:git
commands:
- git fetch --tags -f

- name: configure-buckets
image: minio/mc:RELEASE.2020-10-03T02-54-56Z
commands:
- sleep 5
- mc config host add minio http://minio:9000 AKIAIOSFODNN7EXAMPLE wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
- mc mb --region=eu-west-1 minio/drone-cache-bucket
- mc admin user add minio foo barbarbar
- "echo '{\"Version\": \"2012-10-17\", \"Statement\": [ { \"Action\": [ \"s3:GetObject\", \"s3:PutObject\", \"s3:DeleteObject\", \"s3:CreateBucket\", \"s3:DeleteBucket\" ], \"Effect\": \"Allow\", \"Resource\": [ \"arn:aws:s3:::s3-round-trip-with-role/*\", \"arn:aws:s3:::s3-round-trip-with-role\" ], \"Sid\": \"\" } ] }' >> /tmp/policy.json"
- mc admin policy add minio userpolicy /tmp/policy.json
- mc admin policy set minio userpolicy user=foo

- name: build
image: golang:1.14.4-alpine3.12
commands:
- apk add --update make git
- make drone-cache
environment:
CGO_ENABLED: 0

- name: lint
image: golang:1.14.4-alpine3.12
commands:
- apk add --update make git curl
- make lint
environment:
CGO_ENABLED: 0

- name: test
image: golang:1.14.4-alpine3.12
commands:
- go test -mod=vendor -short -cover -tags=integration ./...
environment:
CGO_ENABLED: 0
TEST_S3_ENDPOINT: minio:9000
TEST_GCS_ENDPOINT: http://fakegcs:4443/storage/v1/
TEST_STORAGE_EMULATOR_HOST: fakegcs:4443
TEST_SFTP_HOST: sftp
TEST_AZURITE_URL: azurite:10000
volumes:
- name: testdata
path: /drone/src/tmp/testdata/cache

- name: rebuild-cache
image: drone-cache:MyTestTag
pull: if-not-exists
settings:
bucket: drone-cache-bucket
mount:
- vendor
rebuild: true
region: eu-west-1
path_style: true
endpoint: minio:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

- name: rebuild-cache-with-key
image: drone-cache:MyTestTag
pull: if-not-exists
settings:
bucket: drone-cache-bucket
cache_key: "{{ .Repo.Name }}_{{ checksum \"go.mod\" }}_{{ checksum \"go.sum\" }}_{{ arch }}_{{ os }}"
mount:
- vendor
rebuild: true
region: eu-west-1
path_style: true
endpoint: minio:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

- name: rebuild-cache-with-gzip
image: drone-cache:MyTestTag
pull: if-not-exists
settings:
archive_format: gzip
bucket: drone-cache-bucket
cache_key: gzip
mount:
- vendor
rebuild: true
region: eu-west-1
path_style: true
endpoint: minio:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

- name: rebuild-cache-with-filesystem
image: drone-cache:MyTestTag
pull: if-not-exists
settings:
archive_format: gzip
backend: filesystem
cache_key: volume
mount:
- vendor
rebuild: true
exit_code: true
volumes:
- name: cache
path: /tmp/cache

- name: restore-cache-with-key
image: drone-cache:MyTestTag
pull: if-not-exists
settings:
bucket: drone-cache-bucket
cache_key: "{{ .Repo.Name }}_{{ checksum \"go.mod\" }}_{{ checksum \"go.sum\" }}_{{ arch }}_{{ os }}"
mount:
- vendor
region: eu-west-1
pull: always
restore: true
path_style: true
endpoint: minio:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

- name: restore-cache-with-gzip
image: drone-cache:MyTestTag
pull: if-not-exists
settings:
archive_format: gzip
bucket: drone-cache-bucket
cache_key: gzip
mount:
- vendor
region: eu-west-1
restore: true
path_style: true
endpoint: minio:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

- name: restore-cache-with-filesystem
image: drone-cache:MyTestTag
pull: if-not-exists
settings:
archive_format: gzip
backend: filesystem
cache_key: volume
mount:
- vendor
restore: true
exit_code: true
volumes:
- name: cache
path: /tmp/cache

- name: restore-cache-debug
image: drone-cache:MyTestTag
pull: if-not-exists
settings:
debug: true
restore: true
pull: always

- name: restore-cache
image: drone-cache:MyTestTag
pull: if-not-exists
settings:
bucket: drone-cache-bucket
mount:
- vendor
region: eu-west-1
restore: true
path_style: true
endpoint: minio:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

services:
- name: minio
image: minio/minio:RELEASE.2020-11-06T23-17-07Z
commands:
- minio server /data
environment:
MINIO_ACCESS_KEY: AKIAIOSFODNN7EXAMPLE
MINIO_REGION: eu-west-1
MINIO_SECRET_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
ports:
- 9000
- name: fakegcs
image: fsouza/fake-gcs-server:1.18.3
ports:
- 4443
commands:
- fake-gcs-server -public-host fakegcs -scheme http
- name: sftp
image: atmoz/sftp:alpine
ports:
- 22
commands:
- /entrypoint foo:pass:::sftp_test bar:pass:::plugin_test
- name: azurite
image: mcr.microsoft.com/azure-storage/azurite:3.10.0
commands:
- azurite-blob --blobHost 0.0.0.0
ports:
- 10000

volumes:
- name: cache
temp: {}
- name: testdata
temp: {}

trigger:
branch:
- master
event:
-
...
53 changes: 53 additions & 0 deletions .goreleaser-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
project_name: drone-cache
before:
hooks:
- make clean
- make vendor
dist: target/dist
builds:
-
goos:
- linux
goarch:
- amd64

env:
- CGO_ENABLED=0
flags:
-tags netgo
ldflags: >
-s
-w
-X main.Version={{.Version}}
-X main.Commit={{.ShortCommit}}
-X main.Date={{.Date}}
hooks:
# Ignores failures, this is just best effort. Alternative: find target/dist -name drone-cache -type f -exec upx {} +
post: find target/dist -name drone-cache -type f -print0 | xargs -n 1 -0 upx
checksum:
name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt" # default
snapshot:
name_template: "{{ .Tag }}-SNAPSHOT-{{.ShortCommit}}" # default
dockers:
-
goos: linux
goarch: amd64
goarm: ''

# Modify the image template name here as desired
image_templates:
- "drone-cache:MyTestTag"

dockerfile: Dockerfile
build_flag_templates:
- "--label=org.label-schema.schema-version=1.0"
- "--label=version={{.Version}}"
- "--label=org.label-schema.name={{.ProjectName}}"
- "--label=org.label-schema.version={{.Version}}"
- "--label=org.label-schema.build-date={{.Date}}"
- "--label=org.label-schema.vcs-ref={{.FullCommit}}"
- "--label=org.label-schema.docker.dockerfile=Dockerfile"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- [#99](https://github.com/meltwater/drone-cache/issues/99) Document building images and pushing locally for PR testing
- [#133](https://github.com/meltwater/drone-cache/pull/133) backend/s3: Fixed Anonymous Credentials Error on public buckets.
- Fixes [#132](https://github.com/meltwater/drone-cache/issues/132)
- [#138](https://github.com/meltwater/drone-cache/pull/138) backend/gcs: Fix GCS to pass credentials correctly when `GCS_ENDPOINT` is not set.
Expand All @@ -20,11 +21,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#86](https://github.com/meltwater/drone-cache/pull/86) Add backend operation timeout option that cancels request if they take longer than given duration. `BACKEND_OPERATION_TIMEOUT`, `backend.operation-timeot`. Default value is `3 minutes`.
- [#86](https://github.com/meltwater/drone-cache/pull/86) Customize the cache key in the path. Adds a new `remote_root` option to customize it. Defaults to `repo.name`.
- Fixes [#97](https://github.com/meltwater/drone-cache/issues/97).
[#89](https://github.com/meltwater/drone-cache/pull/89) Add Azure Storage Backend.
[#84](https://github.com/meltwater/drone-cache/pull/84) Adds compression level option.
[#77](https://github.com/meltwater/drone-cache/pull/77) Adds a new hidden CLI flag to be used for tests.
[#73](https://github.com/meltwater/drone-cache/pull/73) Add Google Cloud storage support
[#68](https://github.com/meltwater/drone-cache/pull/68) Introduces new storage backend, sFTP.
[#89](https://github.com/meltwater/drone-cache/pull/89) Add Azure Storage Backend.
[#84](https://github.com/meltwater/drone-cache/pull/84) Adds compression level option.
[#77](https://github.com/meltwater/drone-cache/pull/77) Adds a new hidden CLI flag to be used for tests.
[#73](https://github.com/meltwater/drone-cache/pull/73) Add Google Cloud storage support
[#68](https://github.com/meltwater/drone-cache/pull/68) Introduces new storage backend, sFTP.

### Changed

Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ the requirements below.
7. Update [plugin index](https://github.com/drone/drone-plugin-index/blob/master/content/meltwater/drone-cache/index.md) using [DOCS](./DOCS.md).

> **Keep in mind that users usually use the `latest` tagged images in their pipeline, please make sure you do not interfere with their working workflow.**

## Testing Locally

Want to test locally without opening a PR? Follow the steps below to build a local image of drone-cache and run the Drone pipeline against it.

0. Make sure you have the [Drone CLI](https://docs.drone.io/cli/install/), [Docker](https://docs.docker.com/get-docker/), and [GoReleaser](https://goreleaser.com/install/) installed locally.
1. Update the `image_templates` key in `drone-cache/.goreleaser-local.yml` to reflect the name you'd like your image to have, then run `goreleaser release --config=.goreleaser-local.yml --snapshot --skip-publish --rm-dist` to build the image.
2. Update the `image: drone-cache:MyTestTag` entries in the `local-pipeline` pipeline in the `.drone.yml` with the name of the image that you created (there are several of these).
3. Run the Drone pipeline locally with `drone exec ./.drone-local.yml --branch MyBranchName`