Skip to content

Commit a4f2bc3

Browse files
committed
update pipeline, Dockerfile and Taskfile
1 parent d306625 commit a4f2bc3

3 files changed

Lines changed: 35 additions & 144 deletions

File tree

.gitlab-ci.yml

Lines changed: 14 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,18 @@
11
stages:
2-
# - mr-checks
2+
- install-dependencies
33
- build
44
- update-version
5-
# - deploy
6-
# - code-test
7-
5+
#- check_registries
86
include:
9-
# - local: .cicd/telegram.yml
10-
11-
12-
build-docker-image:
13-
#extends: [.telegram]
14-
15-
stage: build
16-
tags:
17-
- aether-runner
18-
image: golang:1.25
19-
services:
20-
- name: docker:20.10-dind
21-
alias: docker
22-
command: ["--insecure-registry=192.168.12.15:8083"]
23-
variables:
24-
DOCKER_TLS_CERTDIR: "" # desactiva TLS para simplificar
25-
DOCKER_HOST: tcp://docker:2375
26-
DOCKER_DRIVER: overlay2
27-
before_script:
28-
- apt-get update && apt-get install -y docker.io
29-
- docker version
30-
script:
31-
- docker info
32-
33-
- docker login --username $CI_REGISTRY_USER --password $CI_REGISTRY_PASSWORD $CI_REGISTRY
34-
35-
- apk update && apk add --no-cache make bash git wget
36-
37-
# - wget https://go.dev/dl/go1.25.0.linux-amd64.tar.gz
38-
39-
# - rm -rf /usr/local/go && tar -C /usr/local -xzf go1.25.0.linux-amd64.tar.gz
40-
41-
# - export PATH=$PATH:/usr/local/go/bin
42-
43-
# - go version
44-
45-
- echo "NF_VERSION=$(make -s -f Makefile print-tag)" > variables.env
46-
47-
- echo "CI_PROJECT_NAME=$(make -s -f Makefile print-target)" >> variables.env
48-
49-
- echo "BRANCH=$(make -s -f Makefile print-branch)" >> variables.env
50-
51-
- make docker-build
52-
53-
- make docker-push
54-
55-
- docker container prune --force
56-
57-
- docker image prune --force
58-
59-
- echo "Build and push of image completed!"
60-
61-
rules:
62-
# Caso 1: MR a main
63-
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"'
64-
65-
# Caso 2: MR a dev
66-
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"'
67-
68-
# Caso 3: Push directo a main (NO desde un merge request)
69-
- if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push" && $CI_MERGE_REQUEST_ID == null'
70-
71-
# Caso 4: Push directo a dev (NO desde un merge request)
72-
- if: '$CI_COMMIT_BRANCH == "dev" && $CI_PIPELINE_SOURCE == "push" && $CI_MERGE_REQUEST_ID == null'
73-
74-
75-
artifacts:
76-
reports:
77-
dotenv: variables.env
78-
79-
needs: []
80-
81-
82-
update-helm-values:
83-
stage: update-version
84-
image: alpine:3.19
85-
tags:
86-
- aether-runner
87-
before_script:
88-
- apk add --no-cache git bash curl
89-
- git config --global user.email "ci-bot@aether.local"
90-
- git config --global user.name "CI Bot"
91-
# - wget -qO /usr/local/bin/yq-go https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
92-
# - chmod +x /usr/local/bin/yq-go
93-
94-
script:
95-
# 1. Clonar repo de infra (OnRamp)
96-
- git clone https://$TOKEN_USER:$ONRAMP_TOKEN@$GITLAB_SERVER_URL/5g/aether.git
97-
- cd aether
98-
99-
# 2. Crear rama nueva (basada en dev)
100-
- BRANCH_NAME="update-${BRANCH}"
101-
- git checkout dev
102-
- git pull origin dev
103-
- git checkout -b $BRANCH_NAME
104-
105-
# 3. Editar values.yaml (ejemplo: cambiar tag de la NF)
106-
# - yq e -i '.amf.image.tag = env(NF_VERSION)' charts/aether/values.yaml
107-
# - yq-go e -i '.["5g-control-plane"].images.tags.amf = env(NF_VERSION)' deps/5gc/roles/core/templates/sdcore-5g-values.yaml
108-
- sed -i -E 's|^([[:space:]]{6}simapp:[[:space:]]*).*|\1'"$NF_VERSION"'|' deps/5gc/roles/core/templates/sdcore-5g-values.yaml
109-
110-
111-
# 4. Commit y push
112-
- git add deps/5gc/roles/core/templates/sdcore-5g-values.yaml
113-
- git commit -m "Update ${CI_PROJECT_NAME} image to ${NF_VERSION}"
114-
- git push origin $BRANCH_NAME
115-
116-
# 5. Crear MR automáticamente vía API de GitLab
117-
- |
118-
curl --header "PRIVATE-TOKEN: $ONRAMP_TOKEN" \
119-
-X POST "https://${GITLAB_SERVER_URL}/api/v4/projects/1268/merge_requests" \
120-
--data "source_branch=$BRANCH_NAME" \
121-
--data "target_branch=dev" \
122-
--data-urlencode "title=Update ${CI_PROJECT_NAME} image to ${NF_VERSION}" \
123-
--data "remove_source_branch=true"
124-
125-
needs:
126-
- job: build-docker-image
127-
artifacts: true
128-
129-
rules:
130-
# Caso 1: MR a main
131-
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"'
132-
133-
# Caso 2: MR a dev
134-
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"'
135-
136-
# Caso 3: Push directo a main (NO desde un merge request)
137-
- if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push" && $CI_MERGE_REQUEST_ID == null'
138-
139-
# Caso 4: Push directo a dev (NO desde un merge request)
140-
- if: '$CI_COMMIT_BRANCH == "dev" && $CI_PIPELINE_SOURCE == "push" && $CI_MERGE_REQUEST_ID == null'
141-
7+
- component: $CI_SERVER_FQDN/5g/cicd-components/building-main-fast@main
8+
inputs:
9+
stage: build
10+
stage_helm: update-version
11+
tags: [aether-runner-3]
12+
project_id: "1268" # OnRamp
13+
nfs_name: "simapp"
14+
rules:
15+
- if: '$CI_COMMIT_REF_NAME == "main"'
16+
when: always
17+
- if: '$CI_COMMIT_REF_NAME == "dev"'
18+
when: always

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ RUN apt-get update && \
1414
RUN go install github.com/go-task/task/v3/cmd/task@latest
1515

1616
WORKDIR $GOPATH/src/simapp
17+
18+
COPY go.mod .
19+
COPY go.sum .
20+
COPY Taskfile.yml .
21+
22+
RUN task mod-start
23+
1724
COPY . .
1825
RUN task build
1926

@@ -27,8 +34,8 @@ ARG DEBUG_TOOLS
2734

2835
# Install debug tools ~ 50MB (if DEBUG_TOOLS is set to true)
2936
RUN if [ "$DEBUG_TOOLS" = "true" ]; then \
30-
apk update && apk add --no-cache -U gcompat vim strace net-tools curl netcat-openbsd bind-tools bash; \
31-
fi
37+
apk update && apk add --no-cache -U gcompat vim strace net-tools curl netcat-openbsd bind-tools bash; \
38+
fi
3239

3340
# Copy executable
3441
COPY --from=builder /go/src/simapp/bin/* /usr/local/bin/.

Taskfile.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
# SPDX-License-Identifier: Apache-2.0
44
# Taskfile equivalent to simapp Makefile
55

6-
version: '3'
6+
version: "3"
77

88
vars:
99
PROJECT_NAME: sdcore
1010
DOCKER_VERSION:
1111
sh: cat ./VERSION 2>/dev/null || echo "latest"
12-
12+
1313
# Docker related
1414
DOCKER_REGISTRY: ""
1515
DOCKER_REPOSITORY: ""
1616
DOCKER_TAG: "{{.DOCKER_VERSION}}"
1717
DOCKER_IMAGENAME: "{{.DOCKER_REGISTRY}}{{.DOCKER_REPOSITORY}}{{.PROJECT_NAME}}:{{.DOCKER_TAG}}"
1818
DOCKER_BUILDKIT: 1
1919
DOCKER_BUILD_ARGS: ""
20-
20+
2121
# Docker labels
2222
DOCKER_LABEL_VCS_URL:
2323
sh: git remote get-url $(git remote) 2>/dev/null || echo "unknown"
@@ -37,13 +37,13 @@ vars:
3737
fi
3838
DOCKER_LABEL_BUILD_DATE:
3939
sh: date -u "+%Y-%m-%dT%H:%M:%SZ"
40-
40+
4141
DOCKER_TARGETS: simapp
4242
GO_BIN_PATH: bin
4343
GO_SRC_PATH: ./
4444
NF: simapp
4545
GO_NF: simapp
46-
46+
4747
# Build info
4848
VERSION:
4949
sh: git describe --tags 2>/dev/null || echo "dev"
@@ -109,6 +109,13 @@ tasks:
109109
-v \
110110
./ ./...
111111
112+
mod-start:
113+
desc: "execute go mod download to performance the docker build step"
114+
aliases: [mod]
115+
cmds:
116+
- cd {{.GO_SRC_PATH}}
117+
- go mod download
118+
112119
_coverage-dir:
113120
internal: true
114121
cmds:

0 commit comments

Comments
 (0)