Browse Source

chore: upgrade docker build.

update-packer-186
Bo-Yi Wu 5 years ago
parent
commit
09d2bafa37
  1. 16
      .drone.jsonnet
  2. 446
      .drone.yml
  3. 19
      Dockerfile.i386
  4. 9
      docker/Dockerfile.linux.amd64
  5. 9
      docker/Dockerfile.linux.arm
  6. 11
      docker/Dockerfile.linux.arm64
  7. 25
      docker/manifest.tmpl
  8. 258
      pipeline.libsonnet

16
.drone.jsonnet

@ -0,0 +1,16 @@
local pipeline = import 'pipeline.libsonnet';
local name = 'drone-packer';
[
pipeline.test,
pipeline.build(name, 'linux', 'amd64'),
pipeline.build(name, 'linux', 'arm64'),
pipeline.build(name, 'linux', 'arm'),
pipeline.release,
pipeline.notifications(depends_on=[
'linux-amd64',
'linux-arm64',
'linux-arm',
'release-binary',
]),
]

446
.drone.yml

@ -1,114 +1,368 @@
workspace:
base: /go/src
path: github.com/appleboy/drone-packer
clone:
git:
image: plugins/git
depth: 50
tags: true
pipeline:
lint:
image: golang:1.11
pull: true
---
kind: pipeline
name: testing
platform:
os: linux
arch: amd64
steps:
- name: vet
pull: always
image: golang:1.13
commands:
- make vet
- make revive
- make test-vendor
volumes:
- name: gopath
path: /go
- name: lint
pull: always
image: golang:1.13
commands:
- make lint
volumes:
- name: gopath
path: /go
- name: misspell
pull: always
image: golang:1.13
commands:
- make misspell-check
volumes:
- name: gopath
path: /go
- name: test
pull: always
image: golang:1.13
commands:
- make test
- make coverage
environment:
WEBHOOK_ID:
from_secret: webhook_id
WEBHOOK_TOKEN:
from_secret: webhook_token
volumes:
- name: gopath
path: /go
codecov:
- name: codecov
pull: always
image: robertstettner/drone-codecov
secrets: [ codecov_token ]
files:
- coverage.txt
settings:
token:
from_secret: codecov_token
volumes:
- name: gopath
temp: {}
---
kind: pipeline
name: linux-amd64
platform:
os: linux
arch: amd64
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-packer
environment:
CGO_ENABLED: 0
when:
event: [ push, pull_request ]
event:
exclude:
- tag
build_linux_amd64:
image: golang:1.11
pull: true
group: build
- name: build-tag
pull: always
image: golang:1.13
commands:
- make build_linux_amd64
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-packer
environment:
CGO_ENABLED: 0
when:
event:
- tag
build_linux_i386:
image: golang:1.11
pull: true
group: build
- name: executable
pull: always
image: golang:1.13
commands:
- make build_linux_i386
- ./release/linux/amd64/drone-packer --help
- name: dryrun
pull: always
image: plugins/docker:linux-amd64
settings:
cache_from: appleboy/drone-packer
dockerfile: docker/Dockerfile.linux.amd64
dry_run: true
repo: appleboy/drone-packer
tags: linux-amd64
when:
event:
- pull_request
build_linux_arm64:
image: golang:1.11
pull: true
group: build
- name: publish
pull: always
image: plugins/docker:linux-amd64
settings:
auto_tag: true
auto_tag_suffix: linux-amd64
cache_from: appleboy/drone-packer
daemon_off: false
dockerfile: docker/Dockerfile.linux.amd64
password:
from_secret: docker_password
repo: appleboy/drone-packer
username:
from_secret: docker_username
when:
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- refs/pull/**
- refs/tags/**
depends_on:
- testing
---
kind: pipeline
name: linux-arm64
platform:
os: linux
arch: arm64
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-packer
environment:
CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.13
commands:
- make build_linux_arm64
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-packer
environment:
CGO_ENABLED: 0
when:
event:
- tag
build_linux_arm:
image: golang:1.11
pull: true
group: build
- name: executable
pull: always
image: golang:1.13
commands:
- make build_linux_arm
publish_linux_amd64:
image: plugins/docker:17.05
pull: true
secrets: [ docker_username, docker_password ]
group: release
repo: ${DRONE_REPO}
- ./release/linux/arm64/drone-packer --help
- name: dryrun
pull: always
image: plugins/docker:linux-arm64
settings:
cache_from: appleboy/drone-packer
dockerfile: docker/Dockerfile.linux.arm64
dry_run: true
repo: appleboy/drone-packer
tags: linux-arm64
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-arm64
settings:
auto_tag: true
dockerfile: Dockerfile
auto_tag_suffix: linux-arm64
cache_from: appleboy/drone-packer
daemon_off: false
dockerfile: docker/Dockerfile.linux.arm64
password:
from_secret: docker_password
repo: appleboy/drone-packer
username:
from_secret: docker_username
when:
event: [ push, tag ]
local: false
# publish_linux_arm:
# image: plugins/docker:17.05
# pull: true
# secrets: [ docker_username, docker_password ]
# group: release
# repo: ${DRONE_REPO}
# auto_tag: true
# auto_tag_suffix: arm
# dockerfile: Dockerfile.arm
# when:
# event: [ push, tag ]
# local: false
# publish_linux_arm64:
# image: plugins/docker:17.05
# pull: true
# secrets: [ docker_username, docker_password ]
# group: release
# repo: ${DRONE_REPO}
# auto_tag: true
# auto_tag_suffix: arm64
# dockerfile: Dockerfile.arm64
# when:
# event: [ push, tag ]
# local: false
# publish_linux_i386:
# image: plugins/docker:17.05
# pull: true
# secrets: [ docker_username, docker_password ]
# group: release
# repo: ${DRONE_REPO}
# auto_tag: true
# auto_tag_suffix: i386
# dockerfile: Dockerfile.i386
# when:
# event: [ push, tag ]
# local: false
discord:
image: appleboy/drone-discord
pull: true
secrets: [ discord_webhook_id, discord_webhook_token ]
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- refs/pull/**
- refs/tags/**
depends_on:
- testing
---
kind: pipeline
name: linux-arm
platform:
os: linux
arch: arm
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-packer
environment:
CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.13
commands:
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-packer
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13
commands:
- ./release/linux/arm/drone-packer --help
- name: dryrun
pull: always
image: plugins/docker:linux-arm
settings:
cache_from: appleboy/drone-packer
dockerfile: docker/Dockerfile.linux.arm
dry_run: true
repo: appleboy/drone-packer
tags: linux-arm
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-arm
settings:
auto_tag: true
auto_tag_suffix: linux-arm
cache_from: appleboy/drone-packer
daemon_off: false
dockerfile: docker/Dockerfile.linux.arm
password:
from_secret: docker_password
repo: appleboy/drone-packer
username:
from_secret: docker_username
when:
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- refs/pull/**
- refs/tags/**
depends_on:
- testing
---
kind: pipeline
name: release-binary
platform:
os: linux
arch: amd64
steps:
- name: build-all-binary
pull: always
image: golang:1.13
commands:
- make release
when:
event:
- tag
- name: deploy-all-binary
pull: always
image: plugins/github-release
settings:
api_key:
from_secret: github_release_api_key
files:
- dist/release/*
when:
status: [ success, failure ]
event:
- tag
trigger:
ref:
- refs/tags/**
depends_on:
- testing
---
kind: pipeline
name: notifications
platform:
os: linux
arch: amd64
steps:
- name: manifest
pull: always
image: plugins/manifest
settings:
ignore_missing: true
password:
from_secret: docker_password
spec: docker/manifest.tmpl
username:
from_secret: docker_username
trigger:
ref:
- refs/heads/master
- refs/tags/**
depends_on:
- linux-amd64
- linux-arm64
- linux-arm
- release-binary
...

19
Dockerfile.i386

@ -1,19 +0,0 @@
FROM plugins/base:multiarch
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone Packer" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
RUN apk add --no-cache ca-certificates \
wget && \
rm -rf /var/cache/apk/*
ENV PACKER_VERSION 1.4.4
ENV PACKER_ARCH 386
RUN wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_${PACKER_ARCH}.zip -O packer.zip && \
unzip packer.zip -d /bin && \
rm -f packer.zip
ADD release/linux/i${PACKER_ARCH}/drone-packer /bin/
ENTRYPOINT ["/bin/drone-packer"]

9
Dockerfile → docker/Dockerfile.linux.amd64

@ -1,19 +1,16 @@
FROM plugins/base:amd64
FROM plugins/base:linux-amd64
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone Packer" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
RUN apk add --no-cache ca-certificates \
wget && \
rm -rf /var/cache/apk/*
ENV PACKER_VERSION 1.4.4
ENV PACKER_ARCH amd64
RUN wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_${PACKER_ARCH}.zip -O packer.zip && \
unzip packer.zip -d /bin && \
rm -f packer.zip
ADD release/linux/amd64/drone-packer /bin/
COPY release/linux/amd64/drone-packer /bin/
ENTRYPOINT ["/bin/drone-packer"]

9
Dockerfile.arm → docker/Dockerfile.linux.arm

@ -1,19 +1,16 @@
FROM plugins/base:multiarch
FROM plugins/base:linux-arm
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone Packer" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
RUN apk add --no-cache ca-certificates \
wget && \
rm -rf /var/cache/apk/*
ENV PACKER_VERSION 1.4.4
ENV PACKER_ARCH arm
RUN wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_${PACKER_ARCH}.zip -O packer.zip && \
unzip packer.zip -d /bin && \
rm -f packer.zip
ADD release/linux/${PACKER_ARCH}/drone-packer /bin/
COPY release/linux/arm/drone-packer /bin/
ENTRYPOINT ["/bin/drone-packer"]

11
Dockerfile.arm64 → docker/Dockerfile.linux.arm64

@ -1,19 +1,16 @@
FROM plugins/base:multiarch
FROM plugins/base:linux-arm64
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone Packer" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
RUN apk add --no-cache ca-certificates \
wget && \
rm -rf /var/cache/apk/*
ENV PACKER_VERSION 1.4.4
ENV PACKER_ARCH arm64
RUN wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_${PACKER_ARCH}.zip -O packer.zip && \
unzip packer.zip -d /bin && \
rm -f packer.zip
rm -f packer.zi
COPY release/linux/arm64/drone-packer /bin/
ADD release/linux/${PACKER_ARCH}/drone-packer /bin/
ENTRYPOINT ["/bin/drone-packer"]

25
docker/manifest.tmpl

@ -0,0 +1,25 @@
image: appleboy/drone-packer:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
- {{this}}
{{/each}}
{{/if}}
manifests:
-
image: appleboy/drone-packer:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
platform:
architecture: amd64
os: linux
-
image: appleboy/drone-packer:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
platform:
architecture: arm64
os: linux
variant: v8
-
image: appleboy/drone-packer:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
platform:
architecture: arm
os: linux
variant: v7

258
pipeline.libsonnet

@ -0,0 +1,258 @@
{
test:: {
kind: 'pipeline',
name: 'testing',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'vet',
image: 'golang:1.13',
pull: 'always',
commands: [
'make vet',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'lint',
image: 'golang:1.13',
pull: 'always',
commands: [
'make lint',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'misspell',
image: 'golang:1.13',
pull: 'always',
commands: [
'make misspell-check',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'test',
image: 'golang:1.13',
pull: 'always',
environment: {
WEBHOOK_ID: { 'from_secret': 'webhook_id' },
WEBHOOK_TOKEN: { 'from_secret': 'webhook_token' },
},
commands: [
'make test',
'make coverage',
],
volumes: [
{
name: 'gopath',
path: '/go',
},
],
},
{
name: 'codecov',
image: 'robertstettner/drone-codecov',
pull: 'always',
settings: {
token: { 'from_secret': 'codecov_token' },
},
},
],
volumes: [
{
name: 'gopath',
temp: {},
},
],
},
build(name, os='linux', arch='amd64'):: {
kind: 'pipeline',
name: os + '-' + arch,
platform: {
os: os,
arch: arch,
},
steps: [
{
name: 'build-push',
image: 'golang:1.13',
pull: 'always',
environment: {
CGO_ENABLED: '0',
},
commands: [
'go build -v -ldflags \'-X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
],
when: {
event: {
exclude: [ 'tag' ],
},
},
},
{
name: 'build-tag',
image: 'golang:1.13',
pull: 'always',
environment: {
CGO_ENABLED: '0',
},
commands: [
'go build -v -ldflags \'-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
],
when: {
event: [ 'tag' ],
},
},
{
name: 'executable',
image: 'golang:1.13',
pull: 'always',
commands: [
'./release/' + os + '/' + arch + '/' + name + ' --help',
],
},
{
name: 'dryrun',
image: 'plugins/docker:' + os + '-' + arch,
pull: 'always',
settings: {
daemon_off: false,
dry_run: true,
tags: os + '-' + arch,
dockerfile: 'docker/Dockerfile.' + os + '.' + arch,
repo: 'appleboy/' + name,
cache_from: 'appleboy/' + name,
},
when: {
event: [ 'pull_request' ],
},
},
{
name: 'publish',
image: 'plugins/docker:' + os + '-' + arch,
pull: 'always',
settings: {
daemon_off: 'false',
auto_tag: true,
auto_tag_suffix: os + '-' + arch,
dockerfile: 'docker/Dockerfile.' + os + '.' + arch,
repo: 'appleboy/' + name,
cache_from: 'appleboy/' + name,
username: { 'from_secret': 'docker_username' },
password: { 'from_secret': 'docker_password' },
},
when: {
event: {
exclude: [ 'pull_request' ],
},
},
},
],
depends_on: [
'testing',
],
trigger: {
ref: [
'refs/heads/master',
'refs/pull/**',
'refs/tags/**',
],
},
},
release:: {
kind: 'pipeline',
name: 'release-binary',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'build-all-binary',
image: 'golang:1.13',
pull: 'always',
commands: [
'make release'
],
when: {
event: [ 'tag' ],
},
},
{
name: 'deploy-all-binary',
image: 'plugins/github-release',
pull: 'always',
settings: {
files: [ 'dist/release/*' ],
api_key: { 'from_secret': 'github_release_api_key' },
},
when: {
event: [ 'tag' ],
},
},
],
depends_on: [
'testing',
],
trigger: {
ref: [
'refs/tags/**',
],
},
},
notifications(os='linux', arch='amd64', depends_on=[]):: {
kind: 'pipeline',
name: 'notifications',
platform: {
os: os,
arch: arch,
},
steps: [
{
name: 'manifest',
image: 'plugins/manifest',
pull: 'always',
settings: {
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
spec: 'docker/manifest.tmpl',
ignore_missing: true,
},
},
],
depends_on: depends_on,
trigger: {
ref: [
'refs/heads/master',
'refs/tags/**',
],
},
},
signature(key):: {
kind: 'signature',
hmac: key,
}
}
Loading…
Cancel
Save