Skip to content

Commit

Permalink
Merge pull request #97 from cxr29/master
Browse files Browse the repository at this point in the history
feat: buildx
  • Loading branch information
sixther-dc authored Jul 12, 2023
2 parents bb386c0 + b61b56a commit 7aac82f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
18 changes: 4 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
FROM registry.erda.cloud/retag/golang:1.16.6 as build

FROM registry.erda.cloud/erda-x/golang:1.17 as build
RUN apt-get update && apt-get -y install libpcap-dev

COPY . /root/build
WORKDIR /root/build

ENV GOPROXY="https://goproxy.cn"
RUN set -ex && echo "Asia/Shanghai" > /etc/timezone

RUN make telegraf

FROM registry.cn-hangzhou.aliyuncs.com/terminus/terminus-centos:base

RUN mkdir -p /app/conf
FROM registry.erda.cloud/erda-x/oraclelinux:7

WORKDIR /app

RUN echo "Asia/Shanghai" >/etc/timezone

RUN yum -y install sysstat
RUN yum -y install ntp
RUN yum -y install libpcap libpcap-devel
RUN mkdir -p /app/conf && yum -y install sysstat ntp libpcap http://mirror.centos.org/$(if [[ $(uname -m) == x86_64 ]]; then echo centos; else echo altarch; fi)/7/updates/$(uname -m)/Packages/libpcap-devel-1.5.3-13.el7_9.$(uname -m).rpm

COPY --from=build /root/build/telegraf /app/
COPY --from=build /root/build/conf /app/conf
Expand Down
23 changes: 16 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ image="${DOCKER_REGISTRY}/erda-telegraf:${v}"

echo "image=${image}"

docker build -t "${image}" \
--label "branch=$(git rev-parse --abbrev-ref HEAD)" \
--label "commit=$(git rev-parse HEAD)" \
--label "build-time=$(date '+%Y-%m-%d %T%z')" \
-f "Dockerfile" .
#docker build -t "${image}" \
# --label "branch=$(git rev-parse --abbrev-ref HEAD)" \
# --label "commit=$(git rev-parse HEAD)" \
# --label "build-time=$(date '+%Y-%m-%d %T%z')" \
# -f "Dockerfile" .
#docker push "${image}"

docker login -u "${DOCKER_REGISTRY_USERNAME}" -p "${DOCKER_REGISTRY_PASSWORD}" "${DOCKER_REGISTRY}"

docker push "${image}"
buildctl --addr tcp://buildkitd.default.svc.cluster.local:1234 \
--tlscacert=/.buildkit/ca.pem \
--tlscert=/.buildkit/cert.pem \
--tlskey=/.buildkit/key.pem \
build \
--frontend dockerfile.v0 \
--opt platform=${PLATFORMS} \
--local context=/.pipeline/container/context/telegraf \
--local dockerfile=/.pipeline/container/context/telegraf \
--output type=image,name=${image},push=true

echo "image=${image}" >> $METAFILE
14 changes: 10 additions & 4 deletions pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
version: "1.1"

on:
name: ""
"on":
push:
branches:
- master
- release/*
tags:
- v*

stages:
- stage:
- git-checkout:
alias: telegraf
description: 代码仓库克隆
params:
depth: 1
- stage:
- extract-repo-version:
alias: extract-repo-version
description: 从 git 代码仓库中解析提交信息,生成仓库版本
params:
git_dir: ${{ dirs.telegraf }}
- stage:
- custom-script:
alias: build-telegraf
description: 运行自定义命令
image: registry.erda.cloud/erda-actions/custom-script-action:2.0-20230423123122-5fd86c2
commands:
- cd ${{ dirs.telegraf }}
- echo $(pwd)
- echo $(ls)
- export DOCKER_REGISTRY=${{ configs.docker_registry }}
- export DOCKER_REGISTRY_USERNAME=${{ configs.docker_registry_username }}
- export DOCKER_REGISTRY_PASSWORD=${{ configs.docker_registry_password }}
- export PLATFORMS=${{ configs.PLATFORMS }}
- export IMAGE_TAG=${{ outputs.extract-repo-version.image_tag }}
- ./build.sh
resources:
Expand All @@ -36,13 +41,14 @@ stages:
- stage:
- release:
alias: release-telegraf
description: 用于打包完成时,向dicehub 提交完整可部署的dice.yml。用户若没在pipeline.yml里定义该action,CI会自动在pipeline.yml里插入该action
params:
check_diceyml: false
dice_yml: ${{ dirs.telegraf }}/erda.yml
tag_version: ${{ outputs.extract-repo-version.version }}
image:
telegraf: ${{ outputs.build-telegraf.image }}
telegraf-app: ${{ outputs.build-telegraf.image }}
telegraf-app-edge: ${{ outputs.build-telegraf.image }}
telegraf-edge: ${{ outputs.build-telegraf.image }}
telegraf-platform: ${{ outputs.build-telegraf.image }}
tag_version: ${{ outputs.extract-repo-version.version }}

0 comments on commit 7aac82f

Please sign in to comment.