Skip to content

Commit

Permalink
try more github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
woodgear committed Aug 12, 2024
1 parent 2ad89a7 commit c63390d
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 47 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/build-openresty.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
build-openresty:
name: Build Openresty
runs-on: ubuntu-22.04
strategy:
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- uses: actions/checkout@v4
- name: Configure Git
Expand All @@ -24,19 +29,26 @@ jobs:
git config user.email "[email protected]"
- uses: docker/setup-buildx-action@v3
- name: build
env:
MATRIX_PLATFORM: "${{ matrix.platform }}"
run: |
./scripts/run-like-github-actions.sh build-nginx
platform=$(echo "$MATRIX_PLATFORM" | sed 's|/|-|g')
echo "artifactPath=./alb-nginx-base-$platform.tar" >> $GITHUB_ENV
echo "artifactName=alb-nginx-base-$platform" >> $GITHUB_ENV
- name: Upload alb-nginx-base images to artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: alb-nginx-base
path: alb-nginx-base.tar
name: ${{ env.artifactName }}
path: ${{ env.artifactPath }}
- name: release
if: ${{ inputs.do_release }}
env:
RELEASE_ME: "${{ github.event.inputs.do_release == 'true' }}"
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
env
./scripts/run-like-github-actions.sh release-nginx
55 changes: 45 additions & 10 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ jobs:
build-alb:
name: Build alb
runs-on: ubuntu-22.04
strategy:
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- uses: actions/checkout@v4
- name: Configure Git
Expand All @@ -47,16 +52,18 @@ jobs:
version-file: ./deploy/chart/alb/Chart.yaml
version-file-extraction-pattern: 'version: v([0-9]*\.[0-9]*\.[0-9]*)'
- uses: docker/setup-buildx-action@v3
- uses: azure/setup-helm@v3
with:
version: '${{ env.HELM_VERSION }}'
- name: test alb go
if: ${{ matrix.platform == 'linux/amd64' }}
env:
MATRIX_PLATFORM: "${{ matrix.platform }}"
run: |
set -x
echo "FROM --platform=\${{ matrix.platform }} | $MATRIX_PLATFORM "
./scripts/run-like-github-actions.sh test-alb-go
- name: build
env:
RELEASE_ME: "${{ github.event.inputs.do_release == 'true' }}"
MATRIX_PLATFORM: "${{matrix.platform }}"
run: |
set -x
./scripts/run-like-github-actions.sh build-alb
Expand All @@ -65,26 +72,54 @@ jobs:
with:
name: alb
path: alb.tar
- name: Upload chart's to artifact
uses: actions/upload-artifact@v3
with:
name: alb-chart
path: alauda-alb2.tgz
- name: test alb nginx
env:
MATRIX_PLATFORM: "${{matrix.platform }}"
run: |
set -x
./scripts/run-like-github-actions.sh test-alb-nginx
release-alb:
name: Release alb
runs-on: ubuntu-22.04
needs: [build-alb]
steps:
- name: cr
uses: helm/[email protected]
with:
install_only: true
- uses: azure/setup-helm@v3
with:
version: '${{ env.HELM_VERSION }}'
- name: Upload chart's to artifact
uses: actions/upload-artifact@v3
with:
name: alb-chart
path: alauda-alb2.tgz
- name: pre-release
env:
RELEASE_ME: "${{ github.event.inputs.do_release == 'true' }}"
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
branch=$(echo "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" | sed 's|/|-|g')
echo "pre-release check: $branch $RELEASE_ME"
if [[ "$RELEASE_ME" == "false" ]] && [[ "$branch" == "master" ]] ;then
./scripts/run-like-github-actions.sh pre-release-alb
exit
fi
echo "not pre release"
- name: release
if: ${{ inputs.do_release }}
env:
RELEASE_ME: "${{ github.event.inputs.do_release == 'true' }}"
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
./scripts/run-like-github-actions.sh release-alb
if [[ "$RELEASE_ME" == "true" ]];then
./scripts/run-like-github-actions.sh release-alb
exit
fi
echo "not release"
45 changes: 37 additions & 8 deletions scripts/alb-test-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,49 @@ function alb-go-unit-test() {
}

function alb-envtest-install() {
curl --progress-bar -sSLo envtest-bins.tar.gz $(_switch_url "https://go.kubebuilder.io/test-tools/1.24.2/$(go env GOOS)/$(go env GOARCH)" "http://prod-minio.alauda.cn:80/acp/envtest-bins.1.24.2.tar.gz")
curl --progress-bar -sSLo envtest-bins.tar.gz $(__at_resolve_url envtest)
mkdir -p /usr/local/kubebuilder
tar -C /usr/local/kubebuilder --strip-components=1 -zvxf envtest-bins.tar.gz
rm envtest-bins.tar.gz
ls /usr/local/kubebuilder
/usr/local/kubebuilder/bin/kube-apiserver --version
}

function _switch_url() {
function __at_resolve_url() {
local name="$1"
local arch=$(uname -m)

local envtest_url="https://go.kubebuilder.io/test-tools/1.24.2/$(go env GOOS)/$(go env GOARCH)"
local cfg=$(
cat <<EOF
{
"kubectl_x86_64_online": "https://dl.k8s.io/v1.24.1/kubernetes-client-linux-amd64.tar.gz",
"helm_x86_64_online": "https://mirrors.huaweicloud.com/helm/v3.9.3/helm-v3.9.3-linux-amd64.tar.gz",
"golangcli_x86_64_online": "https://github.com/golangci/golangci-lint/releases/download/v1.59.1/golangci-lint-1.59.1-illumos-amd64.tar.gz",
"envtest_x86_64_online": "$envtest_url",
"kubectl_arm_online": "https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz",
"helm_arm_online": "https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz",
"golangcli_arm_online": "https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz",
"envtest_arm_online": "$envtest_url",
"kubectl_x86_64_offline": "http://prod-minio.alauda.cn/acp/ci/alb/build/kubernetes-client-linux-amd64.tar.gz",
"helm_x86_64_offline": "http://prod-minio.alauda.cn/acp/ci/alb/build/helm-v3.9.3-linux-amd64.tar.gz",
"golangcli_x86_64_offline": "http://prod-minio.alauda.cn/acp/ci/alb/build/golangci-lint-1.59.1-illumos-amd64.tar.gz",
"envtest_x86_64_offline": "http://prod-minio.alauda.cn:80/acp/envtest-bins.1.24.2.tar.gz"
}
EOF
)
local mode="offline"
if [[ -n "$ALB_ONLINE" ]]; then
echo $1
else
echo $2
mode="online"
fi
local url=$(echo "$cfg" | jq -r ".${name}_${arch}_${mode}")
if [[ -z "$url" ]]; then
echo "not found $name $arch $mode"
return 1
fi
echo $url
}

function alb-install-golang-test-dependency() {
Expand All @@ -117,7 +146,7 @@ function alb-install-golang-test-dependency() {
if [ -f "$(which helm)" ]; then echo "dependency already installed" return; else echo "dependency not installed. install it"; fi

# rm -rf kubernetes-client-linux-amd64.tar.gz && wget &&
local kubectl_url=$(_switch_url https://dl.k8s.io/v1.24.1/kubernetes-client-linux-amd64.tar.gz http://prod-minio.alauda.cn/acp/ci/alb/build/kubernetes-client-linux-amd64.tar.gz)
local kubectl_url=$(__at_resolve_url kubectl)

wget $kubectl_url
tar -zxvf kubernetes-client-linux-amd64.tar.gz
Expand All @@ -129,13 +158,13 @@ function alb-install-golang-test-dependency() {
which kubectl

echo "install helm"
local helm_url=$(_switch_url https://mirrors.huaweicloud.com/helm/v3.9.3/helm-v3.9.3-linux-amd64.tar.gz http://prod-minio.alauda.cn/acp/ci/alb/build/helm-v3.9.3-linux-amd64.tar.gz)
local helm_url=$(__at_resolve_url helm)
wget $helm_url
tar -zxvf helm-v3.9.3-linux-amd64.tar.gz && chmod +x ./linux-amd64/helm && mv ./linux-amd64/helm /usr/local/bin/helm && rm -rf ./linux-amd64 && rm ./helm-v3.9.3-linux-amd64.tar.gz

helm version
# url -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2
local golangci_lint=$(_switch_url "https://github.com/golangci/golangci-lint/releases/download/v1.59.1/golangci-lint-1.59.1-illumos-amd64.tar.gz" "http://prod-minio.alauda.cn/acp/ci/alb/build/golangci-lint-1.59.1-illumos-amd64.tar.gz")
local golangci_lint=$(__at_resolve_url golangcli)
wget $golangci_lint
tar -zxvf ./golangci-lint-1.59.1-illumos-amd64.tar.gz
chmod +x ./golangci-lint-1.59.1-illumos-amd64/golangci-lint && mv ./golangci-lint-1.59.1-illumos-amd64/golangci-lint /usr/local/bin/golangci-lint
Expand Down
2 changes: 1 addition & 1 deletion scripts/go-test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
pwd
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
apk add bash
apk add bash curl jq
bash -c 'ALB=$PWD;source ./scripts/alb-dev-actions.sh;alb-test-all-in-ci-golang'
2 changes: 1 addition & 1 deletion scripts/nginx-test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
pwd
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
apk add bash
apk add bash curl jq
bash -c 'ALB=$PWD;source ./template/actions/alb-nginx.sh;alb-test-all-in-ci-nginx'
6 changes: 4 additions & 2 deletions scripts/run-like-ci-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ if [ -n "$USE_PROXY" ]; then
proxy="--network=host -e http_proxy=$HTTP_PROXY -e https_proxy=$HTTPS_PROXY "
fi
base=${1-$(cat ./Dockerfile | grep GO_BUILD_BASE | awk -F = '{print $2}')}
echo "$base"
docker run $proxy -v $PWD:/acp-alb-test -e ALB_ONLINE=$ALB_ONLINE -t $base sh -c "cd /acp-alb-test ;/acp-alb-test/scripts/go-test.sh"
echo "base $base"
platform=${MATRIX_PLATFORM:-linux/amd64}
echo "platform $platform"
docker run $proxy -v $PWD:/acp-alb-test --platform $platform -e ALB_ONLINE=$ALB_ONLINE -t $base sh -c "cd /acp-alb-test ;/acp-alb-test/scripts/go-test.sh"
5 changes: 4 additions & 1 deletion scripts/run-like-ci-nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ if [ -n "$1" ]; then
image="$1"
fi
# image=alb-nginx:test
docker run --user root --network=host -v $PWD:/acp-alb-test -t $image sh -c 'cd /acp-alb-test ;/acp-alb-test/scripts/nginx-test.sh'

platform=${MATRIX_PLATFORM:-linux/amd64}
echo "platform $platform"
docker run --user root --network=host --platform $platform -v $PWD:/acp-alb-test -t $image sh -c 'cd /acp-alb-test ;/acp-alb-test/scripts/nginx-test.sh'
68 changes: 47 additions & 21 deletions scripts/run-like-github-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ function alb-gh-build-alb() (
local alb_nginx_base="$IMAGE_REPO/alb-nginx-base:$(alb-gh-get-nginx-ver)"
local go_build_base="docker.io/library/golang:$(alb-gh-get-gobuild-ver)"
# build images

local platform=${MATRIX_PLATFORM:-"linux/amd64"}
echo "platform $platform"
docker buildx build \
--network=host \
--platform linux/amd64 \
--platform $platform \
-t $IMAGE_REPO/alb:$chart_ver \
--build-arg GO_BUILD_BASE=$go_build_base \
--build-arg ALB_ONLINE=true \
Expand All @@ -52,31 +55,34 @@ function alb-gh-build-alb() (
return
)

# we want each master are usable
function alb-gh-pre-release-alb() (
echo "do pre-release"
local version=$(alb-github-gen-version)
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker tag $IMAGE_REPO/alb:$version $IMAGE_REPO/alb:v0.0.0
docker push $IMAGE_REPO/alb:v0.0.0

rm -rf .cr-release-packages
mkdir -p .cr-release-packages
local chart=$(alb-build-github-chart $IMAGE_REPO v0.0.0 ./deploy/chart/alb .cr-release-packages/)
echo "chart $chart"
cp $chart alauda-alb2.tgz

)

function alb-gh-release-alb() (
if [[ "$RELEASE_ME" != "true" ]]; then
echo "skip release"
return
fi
echo "in release"
# push docker
source ./scripts/alb-dev-actions.sh
export VERSION=$(alb-github-gen-version)
local version=$(alb-github-gen-version)
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push $IMAGE_REPO/alb:$VERSION
docker push $IMAGE_REPO/alb:$version

# push chart
owner=$(cut -d '/' -f 1 <<<"$GITHUB_REPOSITORY")
repo=$(cut -d '/' -f 2 <<<"$GITHUB_REPOSITORY")

args=(--owner "$owner" --repo "$repo" --charts-dir "./deploy/chart/alb" --skip-packaging "true" --pages-branch "gh-pages")

echo "sync chart"
git status
git log | head -n 30
git remote -v
git remote update
git branch -r

.github/cr.sh "${args[@]}"
return
)
Expand All @@ -86,19 +92,25 @@ function alb-gh-build-nginx() (
local RESTY_PCRE_VERSION=$(cat ./template/Dockerfile.openresty | grep RESTY_PCRE_VERSION= | awk -F = '{print $2}' | tr -d '"')
local RESTY_PCRE_BASE="https://downloads.sourceforge.net/project/pcre/pcre/$RESTY_PCRE_VERSION/pcre-$RESTY_PCRE_VERSION.tar.gz"
local resty_base="docker.io/library/alpine"

local platform=${MATRIX_PLATFORM:-"linux/amd64"}
echo "platform $platform"
docker buildx build \
--progress=plain \
--network=host \
--platform $platform \
--no-cache \
--network=host \
--platform linux/amd64 \
-t $IMAGE_REPO/alb-nginx-base:$ver \
--build-arg RESTY_IMAGE_BASE=$resty_base \
--build-arg RESTY_PCRE_BASE=$RESTY_PCRE_BASE \
-o type=docker \
-f ./template/Dockerfile.openresty \
./
docker images
docker save $IMAGE_REPO/alb-nginx-base:$ver >alb-nginx-base.tar
docker image inspect $IMAGE_REPO/alb-nginx-base:$ver
local suffix=$(__normal_platform)
echo "export ./alb-nginx-base-$suffix.tar"
docker save $IMAGE_REPO/alb-nginx-base:$ver >./alb-nginx-base-$suffix.tar
return
)

Expand All @@ -111,22 +123,33 @@ function alb-gh-release-nginx() (
)

function alb-gh-get-nginx-ver() (
cat ./Dockerfile | grep OPENRESTY_BASE | grep alb-nginx | awk -F : '{print $2}'
cat ./Dockerfile | grep OPENRESTY_BASE | grep alb-nginx | awk -F : '{print $2}' | xargs
)

function alb-gh-get-gobuild-ver() (
cat ./Dockerfile | grep GO_BUILD_BASE= | awk -F : '{print $2}'
)

function alb-github-gen-version() {
function alb-gh-ami-master() {
local branch=$(echo "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" | sed 's|/|-|g')
if [[ "$branch" == "master" ]]; then
echo "true"
return
fi
echo "false"
}

function alb-github-gen-version() {
if [[ "$(alb-gh-ami-master)" == "true" ]]; then
echo v$CURRENT_VERSION
return
fi
echo "v$CURRENT_VERSION-$branch.$GITHUB_RUN_NUMBER.$GITHUB_RUN_ATTEMPT"
}

function __normal_platform() {
echo "$MATRIX_PLATFORM" | sed 's|/|-|g'
}
function alb-build-github-chart() {
# alb-build-github-chart $RELEASE_TAG ./chart/alb ./xx
local repo=$1
Expand Down Expand Up @@ -171,4 +194,7 @@ if [ "$0" = "$BASH_SOURCE" ]; then
if [[ "$1" == "release-alb" ]]; then
alb-gh-release-alb
fi
if [[ "$1" == "pre-release-alb" ]]; then
alb-gh-pre-release-alb
fi
fi
2 changes: 2 additions & 0 deletions template/Dockerfile.debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM alpine:latest
RUN echo "Hello, World!"

0 comments on commit c63390d

Please sign in to comment.