Skip to content

Commit 9e19f35

Browse files
rootduanhongyi
root
authored andcommitted
chore(container): add container image
1 parent e28a40d commit 9e19f35

File tree

8 files changed

+230
-31
lines changed

8 files changed

+230
-31
lines changed

.woodpecker/build-binary.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
labels:
2+
type: exec
3+
platform: linux/amd64
4+
5+
steps:
6+
- name: build-binary
7+
image: bash
8+
commands:
9+
- sed -i "s#canary#$CI_COMMIT_TAG#g" version/version.go
10+
- VERSION=$CI_COMMIT_TAG make build-binary
11+
environment:
12+
CODENAME:
13+
from_secret: codename
14+
DEV_REGISTRY:
15+
from_secret: dev_registry
16+
DRYCC_REGISTRY:
17+
from_secret: drycc_registry
18+
CONTAINER_USERNAME:
19+
from_secret: container_username
20+
CONTAINER_PASSWORD:
21+
from_secret: container_password
22+
when:
23+
event:
24+
- push
25+
- tag
26+
27+
- name: publish-binary
28+
image: bash
29+
commands:
30+
- podman run --rm
31+
-e DRONE_BUILD_EVENT=tag
32+
-e DRONE_REPO_OWNER="$CI_REPO_OWNER"
33+
-e DRONE_REPO_NAME="$CI_REPO_NAME"
34+
-e PLUGIN_API_KEY="$GITHUB_TOKEN"
35+
-e PLUGIN_BASE_URL="https://api.github.com/"
36+
-e PLUGIN_UPLOAD_URL="https://uploads.github.com/"
37+
-e DRONE_COMMIT_REF="refs/tags/$CI_COMMIT_TAG"
38+
-e PLUGIN_OVERWRITE="true"
39+
-e PLUGIN_FILES="_dist/*"
40+
-v $(pwd):$(pwd)
41+
-w $(pwd)
42+
docker.io/plugins/github-release
43+
environment:
44+
GITHUB_TOKEN:
45+
from_secret: github_token
46+
when:
47+
event:
48+
- tag
49+
50+
depends_on:
51+
- test-linux

.woodpecker/build-linux.yml

+12-28
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
matrix:
2+
platform:
3+
- linux/amd64
4+
- linux/arm64
5+
16
labels:
27
type: exec
3-
platform: linux/amd64
8+
platform: ${platform}
49

510
steps:
6-
- name: build-linux
11+
- name: publish-linux
712
image: bash
813
commands:
9-
- sed -i "s#canary#$CI_COMMIT_TAG#g" version/version.go
10-
- VERSION=$CI_COMMIT_TAG make build
14+
- export VERSION=$([ -z $CI_COMMIT_TAG ] && echo latest || echo $CI_COMMIT_TAG)-$(sed 's#/#-#g' <<< $CI_SYSTEM_PLATFORM)
15+
- echo $CONTAINER_PASSWORD | podman login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
16+
- make podman-build podman-immutable-push
1117
environment:
1218
CODENAME:
1319
from_secret: codename
@@ -23,29 +29,7 @@ steps:
2329
event:
2430
- push
2531
- tag
26-
27-
- name: publish-linux
28-
image: bash
29-
commands:
30-
- podman run --rm
31-
-e DRONE_BUILD_EVENT=tag
32-
-e DRONE_REPO_OWNER="$CI_REPO_OWNER"
33-
-e DRONE_REPO_NAME="$CI_REPO_NAME"
34-
-e PLUGIN_API_KEY="$GITHUB_TOKEN"
35-
-e PLUGIN_BASE_URL="https://api.github.com/"
36-
-e PLUGIN_UPLOAD_URL="https://uploads.github.com/"
37-
-e DRONE_COMMIT_REF="refs/tags/$CI_COMMIT_TAG"
38-
-e PLUGIN_OVERWRITE="true"
39-
-e PLUGIN_FILES="_dist/*"
40-
-v $(pwd):$(pwd)
41-
-w $(pwd)
42-
docker.io/plugins/github-release
43-
environment:
44-
GITHUB_TOKEN:
45-
from_secret: github_token
46-
when:
47-
event:
48-
- tag
32+
- cron
4933

5034
depends_on:
51-
- test-linux
35+
- test-linux

.woodpecker/manifest.tmpl

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
image: registry.drycc.cc/drycc/{{project}}:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}canary{{/if}}
2+
{{#if build.tags}}
3+
tags:
4+
{{#each build.tags}}
5+
- {{this}}
6+
{{/each}}
7+
{{/if}}
8+
manifests:
9+
-
10+
image: registry.drycc.cc/drycc/{{project}}:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-amd64
11+
platform:
12+
architecture: amd64
13+
os: linux
14+
-
15+
image: registry.drycc.cc/drycc/{{project}}:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-arm64
16+
platform:
17+
architecture: arm64
18+
os: linux

.woodpecker/manifest.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
labels:
2+
type: exec
3+
platform: linux/amd64
4+
5+
steps:
6+
- name: generate-manifest
7+
image: bash
8+
commands:
9+
- sed -i "s/{{project}}/$${CI_REPO_NAME}/g" .woodpecker/manifest.tmpl
10+
- sed -i "s/registry.drycc.cc/$${DRYCC_REGISTRY}/g" .woodpecker/manifest.tmpl
11+
environment:
12+
DRYCC_REGISTRY:
13+
from_secret: drycc_registry
14+
when:
15+
event:
16+
- tag
17+
- push
18+
- cron
19+
20+
- name: publish-manifest
21+
image: bash
22+
commands:
23+
- podman run --rm
24+
-e PLUGIN_SPEC=.woodpecker/manifest.tmpl
25+
-e PLUGIN_USERNAME=$CONTAINER_USERNAME
26+
-e PLUGIN_PASSWORD=$CONTAINER_PASSWORD
27+
-e DRONE_TAG=$CI_COMMIT_TAG
28+
-v $(pwd):$(pwd)
29+
-w $(pwd)
30+
docker.io/plugins/manifest
31+
environment:
32+
CONTAINER_USERNAME:
33+
from_secret: container_username
34+
CONTAINER_PASSWORD:
35+
from_secret: container_password
36+
when:
37+
event:
38+
- tag
39+
- push
40+
- cron
41+
42+
depends_on:
43+
- build-linux

Makefile

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# the filepath to this repository, relative to $GOPATH/src
1+
SHORT_NAME ?= workflow-cli
2+
DRYCC_REGISTRY ?= ${DEV_REGISTRY}
3+
4+
include versioning.mk
5+
26
VERSION ?= canary
37
REPO_PATH := github.com/drycc/workflow-cli
48
DEV_ENV_IMAGE := ${DEV_REGISTRY}/drycc/go-dev
@@ -12,15 +16,19 @@ bootstrap:
1216
${DEV_ENV_CMD} go mod vendor
1317

1418
# This is supposed to be run within a container
15-
build:
19+
build-binary:
1620
${DEV_ENV_CMD} scripts/update-translations.sh -g
1721
${DEV_ENV_CMD} scripts/build ${VERSION}
1822

23+
podman-build:
24+
podman build . --build-arg VERSION=${VERSION} --build-arg CODENAME=${CODENAME} -f docker/Dockerfile -t ${IMAGE}
25+
podman tag ${IMAGE} ${MUTABLE_IMAGE}
26+
1927
test-style:
2028
${DEV_ENV_CMD} lint
2129

2230
test-cover:
2331
${DEV_ENV_CMD} test-cover.sh
2432

25-
test: build test-style test-cover
33+
test: build-binary test-style test-cover
2634
${DEV_ENV_CMD} go test -race -cover -coverprofile=coverage.txt -covermode=atomic ./...

docker/Dockerfile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
ARG VERSION
2+
ARG CODENAME
3+
4+
FROM registry.drycc.cc/drycc/go-dev:latest AS build
5+
ADD . /workspace
6+
RUN export GO111MODULE=on \
7+
&& cd /workspace \
8+
&& sed -i "s#canary#$VERSION#g" version/version.go \
9+
&& CGO_ENABLED=0 init-stack go build -o /usr/local/bin/drycc drycc.go
10+
11+
FROM registry.drycc.cc/drycc/base:$CODENAME
12+
13+
ENV DRYCC_UID=1001 \
14+
DRYCC_GID=1001 \
15+
DRYCC_HOME_DIR=/workspace
16+
17+
COPY --from=build /usr/local/bin/drycc /usr/local/bin/drycc
18+
19+
ADD docker/entrypoint.sh /entrypoint.sh
20+
21+
RUN install-packages bash-completion \
22+
&& groupadd drycc --gid ${DRYCC_GID} \
23+
&& useradd drycc -u ${DRYCC_UID} -g ${DRYCC_GID} -s /bin/bash -m -d ${DRYCC_HOME_DIR} \
24+
&& mkdir -p /etc/bash_completion.d \
25+
&& drycc completion bash > /etc/bash_completion.d/drycc \
26+
&& chown ${DRYCC_GID}:${DRYCC_UID} /usr/local/bin \
27+
&& echo 'alias cd="echo \"cd: restricted\"; false"' > ${DRYCC_HOME_DIR}/.bash_aliases \
28+
&& echo 'alias unalias="echo \"unalias: restricted\"; false"' >> ${DRYCC_HOME_DIR}/.bash_aliases \
29+
&& ln -s /usr/bin/ls /usr/local/bin/ls \
30+
&& ln -s /usr/bin/cat /usr/local/bin/cat \
31+
&& ln -s /usr/bin/sed /usr/local/bin/sed \
32+
&& ln -s /usr/bin/find /usr/local/bin/find \
33+
&& ln -s /usr/bin/bash /usr/local/bin/bash \
34+
&& ln -s /usr/bin/mkdir /usr/local/bin/mkdir \
35+
&& ln -s /usr/bin/sleep /usr/local/bin/sleep \
36+
&& ln -s /usr/bin/dircolors /usr/local/bin/dircolors \
37+
&& ln -s /usr/bin/tini /usr/local/bin/tini \
38+
&& ln -s /usr/bin/init-stack /usr/local/bin/init-stack
39+
40+
ENTRYPOINT [ "/entrypoint.sh" ]
41+
42+
ENV PATH=/usr/local/bin
43+
44+
USER ${DRYCC_UID}
45+
WORKDIR ${DRYCC_HOME_DIR}

docker/entrypoint.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
if [ -n "$DRYCC_USER" ] && [ -n "$DRYCC_TOKEN" ] && [ -n "$DRYCC_ENDPOINT" ]; then
4+
mkdir -p ~/.drycc
5+
if [ ! -f ~/.drycc/client.json ]; then
6+
cat > ~/.drycc/client.json <<EOF
7+
{
8+
"username": "${DRYCC_USER}",
9+
"ssl_verify": ${DRYCC_SSL_VERIFY:-true},
10+
"controller": "${DRYCC_ENDPOINT}",
11+
"token": "${DRYCC_TOKEN}",
12+
"response_limit": ${DRYCC_RESPONSE_LIMIT:-0}
13+
}
14+
EOF
15+
fi
16+
fi
17+
18+
_main() {
19+
if [ "$1" == 'bash' ]; then
20+
shift
21+
exec bash "$@"
22+
else
23+
exec drycc "$@"
24+
fi
25+
}
26+
27+
_main "$@"

versioning.mk

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
MUTABLE_VERSION ?= canary
2+
VERSION ?= git-$(shell git rev-parse --short HEAD)
3+
IMAGE_PREFIX ?= drycc
4+
5+
IMAGE := ${DRYCC_REGISTRY}/${IMAGE_PREFIX}/${SHORT_NAME}:${VERSION}
6+
MUTABLE_IMAGE := ${DRYCC_REGISTRY}/${IMAGE_PREFIX}/${SHORT_NAME}:${MUTABLE_VERSION}
7+
8+
info:
9+
@echo "Build tag: ${VERSION}"
10+
@echo "Registry: ${DRYCC_REGISTRY}"
11+
@echo "Immutable tag: ${IMAGE}"
12+
@echo "Mutable tag: ${MUTABLE_IMAGE}"
13+
14+
.PHONY: podman-push
15+
podman-push: podman-immutable-push podman-mutable-push
16+
17+
.PHONY: podman-immutable-push
18+
podman-immutable-push:
19+
podman push ${IMAGE}
20+
21+
.PHONY: podman-mutable-push
22+
podman-mutable-push:
23+
podman push ${MUTABLE_IMAGE}

0 commit comments

Comments
 (0)