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 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
pull: true
commands: commands:
- make vet - make vet
- make revive volumes:
- make test-vendor - 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 - make misspell-check
volumes:
- name: gopath
path: /go
- name: test
pull: always
image: golang:1.13
commands:
- make test - 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 image: robertstettner/drone-codecov
secrets: [ codecov_token ] settings:
files: token:
- coverage.txt 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: when:
event: [ push, pull_request ] event:
exclude:
- tag
build_linux_amd64: - name: build-tag
image: golang:1.11 pull: always
pull: true image: golang:1.13
group: build
commands: 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: - name: executable
image: golang:1.11 pull: always
pull: true image: golang:1.13
group: build
commands: 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: - name: publish
image: golang:1.11 pull: always
pull: true image: plugins/docker:linux-amd64
group: build 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: 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: - name: executable
image: golang:1.11 pull: always
pull: true image: golang:1.13
group: build
commands: commands:
- make build_linux_arm - ./release/linux/arm64/drone-packer --help
publish_linux_amd64: - name: dryrun
image: plugins/docker:17.05 pull: always
pull: true image: plugins/docker:linux-arm64
secrets: [ docker_username, docker_password ] settings:
group: release cache_from: appleboy/drone-packer
repo: ${DRONE_REPO} 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
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: when:
event: [ push, tag ] event:
local: false exclude:
- pull_request
# publish_linux_arm:
# image: plugins/docker:17.05 trigger:
# pull: true ref:
# secrets: [ docker_username, docker_password ] - refs/heads/master
# group: release - refs/pull/**
# repo: ${DRONE_REPO} - refs/tags/**
# auto_tag: true
# auto_tag_suffix: arm depends_on:
# dockerfile: Dockerfile.arm - testing
# when:
# event: [ push, tag ] ---
# local: false kind: pipeline
name: linux-arm
# publish_linux_arm64:
# image: plugins/docker:17.05 platform:
# pull: true os: linux
# secrets: [ docker_username, docker_password ] arch: arm
# group: release
# repo: ${DRONE_REPO} steps:
# auto_tag: true - name: build-push
# auto_tag_suffix: arm64 pull: always
# dockerfile: Dockerfile.arm64 image: golang:1.13
# when: commands:
# event: [ push, tag ] - go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-packer
# local: false environment:
CGO_ENABLED: 0
# publish_linux_i386: when:
# image: plugins/docker:17.05 event:
# pull: true exclude:
# secrets: [ docker_username, docker_password ] - tag
# group: release
# repo: ${DRONE_REPO} - name: build-tag
# auto_tag: true pull: always
# auto_tag_suffix: i386 image: golang:1.13
# dockerfile: Dockerfile.i386 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
# event: [ push, tag ] environment:
# local: false CGO_ENABLED: 0
when:
discord: event:
image: appleboy/drone-discord - tag
pull: true
secrets: [ discord_webhook_id, discord_webhook_token ] - 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: 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>" \ 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