ci: consolidate active app image builds
This commit is contained in:
@@ -0,0 +1,49 @@
|
|||||||
|
package com.lingniu.ingest.historyapp;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class WoodpeckerPipelineTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void dockerPublishUsesOneProductionAppList() throws IOException {
|
||||||
|
String pipeline = Files.readString(repositoryRoot().resolve("woodpecker.yml"));
|
||||||
|
|
||||||
|
assertThat(pipeline)
|
||||||
|
.contains("ACTIVE_APPS=\"gb32960-ingest-app jt808-ingest-app yutong-mqtt-app vehicle-history-app vehicle-analytics-app\"")
|
||||||
|
.contains("- name: docker-build-apps")
|
||||||
|
.doesNotContain("xinda-push-app")
|
||||||
|
.doesNotContain("KAFKA_TOPIC_XINDA_PUSH");
|
||||||
|
|
||||||
|
assertThat(countOccurrences(pipeline, "- name: docker-build-")).isEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int countOccurrences(String value, String needle) {
|
||||||
|
int count = 0;
|
||||||
|
int from = 0;
|
||||||
|
while (true) {
|
||||||
|
int next = value.indexOf(needle, from);
|
||||||
|
if (next < 0) {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
from = next + needle.length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Path repositoryRoot() {
|
||||||
|
Path current = Path.of(System.getProperty("user.dir")).toAbsolutePath();
|
||||||
|
while (current != null) {
|
||||||
|
if (Files.exists(current.resolve("woodpecker.yml"))) {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
current = current.getParent();
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("repository root not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
178
woodpecker.yml
178
woodpecker.yml
@@ -13,7 +13,17 @@ steps:
|
|||||||
commands: |
|
commands: |
|
||||||
cd $CI_WORKSPACE
|
cd $CI_WORKSPACE
|
||||||
|
|
||||||
mvn -B -ntp -am -pl :gb32960-ingest-app,:jt808-ingest-app,:yutong-mqtt-app,:vehicle-history-app,:vehicle-analytics-app package -DskipTests
|
ACTIVE_APPS="gb32960-ingest-app jt808-ingest-app yutong-mqtt-app vehicle-history-app vehicle-analytics-app"
|
||||||
|
ACTIVE_MODULES=""
|
||||||
|
for APP_NAME in $ACTIVE_APPS; do
|
||||||
|
if [ -z "$ACTIVE_MODULES" ]; then
|
||||||
|
ACTIVE_MODULES=":$APP_NAME"
|
||||||
|
else
|
||||||
|
ACTIVE_MODULES="$ACTIVE_MODULES,:$APP_NAME"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
mvn -B -ntp -am -pl "$ACTIVE_MODULES" package -DskipTests
|
||||||
|
|
||||||
BRANCH_NAME=$(echo ${CI_COMMIT_BRANCH:-local} | tr / -)
|
BRANCH_NAME=$(echo ${CI_COMMIT_BRANCH:-local} | tr / -)
|
||||||
PROJECT_VERSION=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)
|
PROJECT_VERSION=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)
|
||||||
@@ -24,7 +34,7 @@ steps:
|
|||||||
echo "Image version: $IMAGE_VERSION"
|
echo "Image version: $IMAGE_VERSION"
|
||||||
echo "$IMAGE_VERSION" > $CI_WORKSPACE/project_version.txt
|
echo "$IMAGE_VERSION" > $CI_WORKSPACE/project_version.txt
|
||||||
|
|
||||||
- name: docker-build-gb32960-ingest-app
|
- name: docker-build-apps
|
||||||
image: docker:24.0.5-cli
|
image: docker:24.0.5-cli
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
@@ -44,162 +54,24 @@ steps:
|
|||||||
from_secret: aliyun_acr_password
|
from_secret: aliyun_acr_password
|
||||||
commands: |
|
commands: |
|
||||||
cd $CI_WORKSPACE
|
cd $CI_WORKSPACE
|
||||||
APP_NAME=gb32960-ingest-app
|
ACTIVE_APPS="gb32960-ingest-app jt808-ingest-app yutong-mqtt-app vehicle-history-app vehicle-analytics-app"
|
||||||
APP_VERSION=$(cat $CI_WORKSPACE/project_version.txt)
|
APP_VERSION=$(cat $CI_WORKSPACE/project_version.txt)
|
||||||
IMAGE=crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/$APP_NAME:$APP_VERSION
|
REGISTRY=crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com
|
||||||
|
NAMESPACE=oneos
|
||||||
docker build \
|
|
||||||
--build-arg APP_NAME=$APP_NAME \
|
|
||||||
--build-arg APP_VERSION=$APP_VERSION \
|
|
||||||
-t $IMAGE .
|
|
||||||
|
|
||||||
printf '%s' "$ALIYUN_ACR_PASSWORD" | docker login \
|
printf '%s' "$ALIYUN_ACR_PASSWORD" | docker login \
|
||||||
--username "$ALIYUN_ACR_USERNAME" \
|
--username "$ALIYUN_ACR_USERNAME" \
|
||||||
--password-stdin \
|
--password-stdin \
|
||||||
crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com
|
"$REGISTRY"
|
||||||
|
|
||||||
docker push $IMAGE
|
for APP_NAME in $ACTIVE_APPS; do
|
||||||
|
IMAGE=$REGISTRY/$NAMESPACE/$APP_NAME:$APP_VERSION
|
||||||
|
echo "Building and pushing $IMAGE"
|
||||||
|
|
||||||
- name: docker-build-jt808-ingest-app
|
docker build \
|
||||||
image: docker:24.0.5-cli
|
--build-arg APP_NAME=$APP_NAME \
|
||||||
when:
|
--build-arg APP_VERSION=$APP_VERSION \
|
||||||
event:
|
-t $IMAGE .
|
||||||
- push
|
|
||||||
- pull_request
|
|
||||||
- manual
|
|
||||||
branch:
|
|
||||||
- master
|
|
||||||
- develop
|
|
||||||
- main
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
environment:
|
|
||||||
ALIYUN_ACR_USERNAME:
|
|
||||||
from_secret: aliyun_acr_username
|
|
||||||
ALIYUN_ACR_PASSWORD:
|
|
||||||
from_secret: aliyun_acr_password
|
|
||||||
commands: |
|
|
||||||
cd $CI_WORKSPACE
|
|
||||||
APP_NAME=jt808-ingest-app
|
|
||||||
APP_VERSION=$(cat $CI_WORKSPACE/project_version.txt)
|
|
||||||
IMAGE=crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/$APP_NAME:$APP_VERSION
|
|
||||||
|
|
||||||
docker build \
|
docker push $IMAGE
|
||||||
--build-arg APP_NAME=$APP_NAME \
|
done
|
||||||
--build-arg APP_VERSION=$APP_VERSION \
|
|
||||||
-t $IMAGE .
|
|
||||||
|
|
||||||
printf '%s' "$ALIYUN_ACR_PASSWORD" | docker login \
|
|
||||||
--username "$ALIYUN_ACR_USERNAME" \
|
|
||||||
--password-stdin \
|
|
||||||
crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com
|
|
||||||
|
|
||||||
docker push $IMAGE
|
|
||||||
|
|
||||||
- name: docker-build-vehicle-history-app
|
|
||||||
image: docker:24.0.5-cli
|
|
||||||
when:
|
|
||||||
event:
|
|
||||||
- push
|
|
||||||
- pull_request
|
|
||||||
- manual
|
|
||||||
branch:
|
|
||||||
- master
|
|
||||||
- develop
|
|
||||||
- main
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
environment:
|
|
||||||
ALIYUN_ACR_USERNAME:
|
|
||||||
from_secret: aliyun_acr_username
|
|
||||||
ALIYUN_ACR_PASSWORD:
|
|
||||||
from_secret: aliyun_acr_password
|
|
||||||
commands: |
|
|
||||||
cd $CI_WORKSPACE
|
|
||||||
APP_NAME=vehicle-history-app
|
|
||||||
APP_VERSION=$(cat $CI_WORKSPACE/project_version.txt)
|
|
||||||
IMAGE=crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/$APP_NAME:$APP_VERSION
|
|
||||||
|
|
||||||
docker build \
|
|
||||||
--build-arg APP_NAME=$APP_NAME \
|
|
||||||
--build-arg APP_VERSION=$APP_VERSION \
|
|
||||||
-t $IMAGE .
|
|
||||||
|
|
||||||
printf '%s' "$ALIYUN_ACR_PASSWORD" | docker login \
|
|
||||||
--username "$ALIYUN_ACR_USERNAME" \
|
|
||||||
--password-stdin \
|
|
||||||
crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com
|
|
||||||
|
|
||||||
docker push $IMAGE
|
|
||||||
|
|
||||||
- name: docker-build-yutong-mqtt-app
|
|
||||||
image: docker:24.0.5-cli
|
|
||||||
when:
|
|
||||||
event:
|
|
||||||
- push
|
|
||||||
- pull_request
|
|
||||||
- manual
|
|
||||||
branch:
|
|
||||||
- master
|
|
||||||
- develop
|
|
||||||
- main
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
environment:
|
|
||||||
ALIYUN_ACR_USERNAME:
|
|
||||||
from_secret: aliyun_acr_username
|
|
||||||
ALIYUN_ACR_PASSWORD:
|
|
||||||
from_secret: aliyun_acr_password
|
|
||||||
commands: |
|
|
||||||
cd $CI_WORKSPACE
|
|
||||||
APP_NAME=yutong-mqtt-app
|
|
||||||
APP_VERSION=$(cat $CI_WORKSPACE/project_version.txt)
|
|
||||||
IMAGE=crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/$APP_NAME:$APP_VERSION
|
|
||||||
|
|
||||||
docker build \
|
|
||||||
--build-arg APP_NAME=$APP_NAME \
|
|
||||||
--build-arg APP_VERSION=$APP_VERSION \
|
|
||||||
-t $IMAGE .
|
|
||||||
|
|
||||||
printf '%s' "$ALIYUN_ACR_PASSWORD" | docker login \
|
|
||||||
--username "$ALIYUN_ACR_USERNAME" \
|
|
||||||
--password-stdin \
|
|
||||||
crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com
|
|
||||||
|
|
||||||
docker push $IMAGE
|
|
||||||
|
|
||||||
- name: docker-build-vehicle-analytics-app
|
|
||||||
image: docker:24.0.5-cli
|
|
||||||
when:
|
|
||||||
event:
|
|
||||||
- push
|
|
||||||
- pull_request
|
|
||||||
- manual
|
|
||||||
branch:
|
|
||||||
- master
|
|
||||||
- develop
|
|
||||||
- main
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
environment:
|
|
||||||
ALIYUN_ACR_USERNAME:
|
|
||||||
from_secret: aliyun_acr_username
|
|
||||||
ALIYUN_ACR_PASSWORD:
|
|
||||||
from_secret: aliyun_acr_password
|
|
||||||
commands: |
|
|
||||||
cd $CI_WORKSPACE
|
|
||||||
APP_NAME=vehicle-analytics-app
|
|
||||||
APP_VERSION=$(cat $CI_WORKSPACE/project_version.txt)
|
|
||||||
IMAGE=crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/$APP_NAME:$APP_VERSION
|
|
||||||
|
|
||||||
docker build \
|
|
||||||
--build-arg APP_NAME=$APP_NAME \
|
|
||||||
--build-arg APP_VERSION=$APP_VERSION \
|
|
||||||
-t $IMAGE .
|
|
||||||
|
|
||||||
printf '%s' "$ALIYUN_ACR_PASSWORD" | docker login \
|
|
||||||
--username "$ALIYUN_ACR_USERNAME" \
|
|
||||||
--password-stdin \
|
|
||||||
crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com
|
|
||||||
|
|
||||||
docker push $IMAGE
|
|
||||||
|
|||||||
Reference in New Issue
Block a user