Browse Source

chore: upgrade docker build.

update-packer-186
Bo-Yi Wu 5 years ago
parent
commit
09d2bafa37
  1. 16
      .drone.jsonnet
  2. 480
      .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',
]),
]

480
.drone.yml

@ -1,114 +1,368 @@
workspace: ---
base: /go/src kind: pipeline
path: github.com/appleboy/drone-packer name: testing
clone: platform:
git: os: linux
image: plugins/git arch: amd64
depth: 50
tags: true steps:
- name: vet
pipeline: pull: always
lint: image: golang:1.13
image: golang:1.11 commands:
pull: true - make vet
commands: volumes:
- make vet - name: gopath
- make revive path: /go
- make test-vendor
- make misspell-check - name: lint
- make test pull: always
image: golang:1.13
codecov: commands:
image: robertstettner/drone-codecov - make lint
secrets: [ codecov_token ] volumes:
files: - name: gopath
- coverage.txt path: /go
when:
event: [ push, pull_request ] - name: misspell
pull: always
build_linux_amd64: image: golang:1.13
image: golang:1.11 commands:
pull: true - make misspell-check
group: build volumes:
commands: - name: gopath
- make build_linux_amd64 path: /go
build_linux_i386: - name: test
image: golang:1.11 pull: always
pull: true image: golang:1.13
group: build commands:
commands: - make test
- make build_linux_i386 - make coverage
environment:
build_linux_arm64: WEBHOOK_ID:
image: golang:1.11 from_secret: webhook_id
pull: true WEBHOOK_TOKEN:
group: build from_secret: webhook_token
commands: volumes:
- make build_linux_arm64 - name: gopath
path: /go
build_linux_arm:
image: golang:1.11 - name: codecov
pull: true pull: always
group: build image: robertstettner/drone-codecov
commands: settings:
- make build_linux_arm token:
from_secret: codecov_token
publish_linux_amd64:
image: plugins/docker:17.05 volumes:
pull: true - name: gopath
secrets: [ docker_username, docker_password ] temp: {}
group: release
repo: ${DRONE_REPO} ---
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:
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/amd64/drone-packer
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13
commands:
- ./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
- 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:
- 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
- name: executable
pull: always
image: golang:1.13
commands:
- ./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 auto_tag: true
dockerfile: Dockerfile auto_tag_suffix: linux-arm64
when: cache_from: appleboy/drone-packer
event: [ push, tag ] daemon_off: false
local: false dockerfile: docker/Dockerfile.linux.arm64
password:
# publish_linux_arm: from_secret: docker_password
# image: plugins/docker:17.05 repo: appleboy/drone-packer
# pull: true username:
# secrets: [ docker_username, docker_password ] from_secret: docker_username
# group: release when:
# repo: ${DRONE_REPO} event:
# auto_tag: true exclude:
# auto_tag_suffix: arm - pull_request
# dockerfile: Dockerfile.arm
# when: trigger:
# event: [ push, tag ] ref:
# local: false - refs/heads/master
- refs/pull/**
# publish_linux_arm64: - refs/tags/**
# image: plugins/docker:17.05
# pull: true depends_on:
# secrets: [ docker_username, docker_password ] - testing
# group: release
# repo: ${DRONE_REPO} ---
# auto_tag: true kind: pipeline
# auto_tag_suffix: arm64 name: linux-arm
# dockerfile: Dockerfile.arm64
# when: platform:
# event: [ push, tag ] os: linux
# local: false arch: arm
# publish_linux_i386: steps:
# image: plugins/docker:17.05 - name: build-push
# pull: true pull: always
# secrets: [ docker_username, docker_password ] image: golang:1.13
# group: release commands:
# repo: ${DRONE_REPO} - go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-packer
# auto_tag: true environment:
# auto_tag_suffix: i386 CGO_ENABLED: 0
# dockerfile: Dockerfile.i386 when:
# when: event:
# event: [ push, tag ] exclude:
# local: false - tag
discord: - name: build-tag
image: appleboy/drone-discord pull: always
pull: true image: golang:1.13
secrets: [ discord_webhook_id, discord_webhook_token ] commands:
when: - go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-packer
status: [ success, failure ] 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:
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>" \ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone Packer" \ org.label-schema.name="Drone Packer" \
org.label-schema.vendor="Bo-Yi Wu" \ org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0" 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_VERSION 1.4.4
ENV PACKER_ARCH amd64 ENV PACKER_ARCH amd64
RUN wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_${PACKER_ARCH}.zip -O packer.zip && \ 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 && \ unzip packer.zip -d /bin && \
rm -f packer.zip rm -f packer.zip
ADD release/linux/amd64/drone-packer /bin/ COPY release/linux/amd64/drone-packer /bin/
ENTRYPOINT ["/bin/drone-packer"] 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>" \ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone Packer" \ org.label-schema.name="Drone Packer" \
org.label-schema.vendor="Bo-Yi Wu" \ org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0" 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_VERSION 1.4.4
ENV PACKER_ARCH arm ENV PACKER_ARCH arm
RUN wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_${PACKER_ARCH}.zip -O packer.zip && \ 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 && \ unzip packer.zip -d /bin && \
rm -f packer.zip rm -f packer.zip
ADD release/linux/${PACKER_ARCH}/drone-packer /bin/ COPY release/linux/arm/drone-packer /bin/
ENTRYPOINT ["/bin/drone-packer"] 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>" \ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone Packer" \ org.label-schema.name="Drone Packer" \
org.label-schema.vendor="Bo-Yi Wu" \ org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0" 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_VERSION 1.4.4
ENV PACKER_ARCH arm64 ENV PACKER_ARCH arm64
RUN wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_${PACKER_ARCH}.zip -O packer.zip && \ 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 && \ 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"] 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