Skip to content

Commit a37a9d7

Browse files
committed
Test.
1 parent 6a8e43f commit a37a9d7

File tree

2 files changed

+4
-172
lines changed

2 files changed

+4
-172
lines changed

.gitlab-ci.yml

-169
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,8 @@
1-
.commands:
2-
setup_silta_cli: |
3-
echo "Install silta-cli"
4-
mkdir -p ~/.local/bin
5-
latest_release_url=$(curl -sL https://api.github.com/repos/wunderio/silta-cli/releases/latest | grep -o -E "https://(.*)silta-(.*)-linux-amd64.tar.gz" | head -1)
6-
curl -sL $latest_release_url | tar xz -C ~/.local/bin
7-
silta version
8-
drupal_composer_install: |
9-
echo "Composer install"
10-
composer install -n --prefer-dist --ignore-platform-reqs --no-dev --optimize-autoloader
11-
npm_install_build: |
12-
echo "Npm install"
13-
npm install && npm run build
14-
setup_silta_proxy: |
15-
echo "Set up silta proxy"
16-
if [[ -n "$TUNNEL_USER_HOST" ]]; then
17-
ssh -o StrictHostKeyChecking=accept-new -D 1337 -C -N -q -f "$TUNNEL_USER_HOST"
18-
echo 'export SILTA_PROXY=socks5://localhost:1337' >> $BASH_ENV
19-
if command -v gcloud &> /dev/null; then
20-
gcloud config set proxy/type socks5
21-
gcloud config set proxy/address 127.0.0.1
22-
gcloud config set proxy/port 1337
23-
fi
24-
if command -v silta &> /dev/null; then
25-
if [ "$CLUSTER_TYPE" == "aws" ] && command -v pproxy &> /dev/null; then
26-
pproxy -r socks5://127.0.0.1:1337 --daemon
27-
silta config set proxy http://localhost:8080
28-
else
29-
silta config set proxy socks5://localhost:1337
30-
fi
31-
fi
32-
echo "Proxy is ready for outgoing connections"
33-
fi
34-
cloud_login: |
35-
echo "Cloud login"
36-
KUBECTL_CONFIG_VAR="${SILTA_CLUSTER_ID}_KUBECTL_CONFIG"
37-
38-
# If project kubectl is set, use it to connect to the cluster.
39-
if [ ! -z "${!KUBECTL_CONFIG_VAR}" ]; then
40-
export KUBECTL_CONFIG="${!KUBECTL_CONFIG_VAR}"
41-
echo "export KUBECTL_CONFIG=${!KUBECTL_CONFIG_VAR}" >> $BASH_ENV
42-
silta cloud login --cluster-name "${CLUSTER_NAME}"
43-
44-
# Otherwise, try to use global credentials and check exit code.
45-
else
46-
set +e
47-
silta cloud login --cluster-name "${CLUSTER_NAME}"
48-
49-
# if exit code is not 0, request kubectl injection via silta dashboard api
50-
if [ $? -ne 0 ]; then
51-
set -e
52-
echo "Cluster connection credentials are missing."
53-
54-
if [ ! -z "${SILTA_DASHBOARD_URL}" ]; then
55-
echo "Attempting to request cluster connection credentials from the Silta Dashboard API."
56-
NAMESPACE="${CIRCLE_PROJECT_REPONAME,,}"
57-
# Request kubeconfig injection from the Silta Dashboard API via curl request.
58-
curl -X POST "${SILTA_DASHBOARD_URL}/api/circleci/reload-ns-rbac" \
59-
-H "Content-type: application/x-www-form-urlencoded" \
60-
-d "rbac_reload_key=${SILTA_DASHBOARD_KEY}" \
61-
-d "cluster=${SILTA_CLUSTER_ID}" \
62-
-d "namespace=${NAMESPACE}"
63-
echo ""
64-
echo "Credentials requested, please rerun the build."
65-
fi
66-
exit 1
67-
fi
68-
fi
69-
docker_login: |
70-
echo "Docker login"
71-
silta ci image login
72-
set_release_name: |
73-
echo "Set release name"
74-
NAMESPACE="${CIRCLE_PROJECT_REPONAME,,}"
75-
# Use branch name or fall back to "production" if it's a tag.
76-
BRANCHNAME="${CIRCLE_BRANCH:-${CIRCLE_TAG:+production}}"
77-
78-
RELEASE_NAME=$(silta ci release name --branchname "${BRANCHNAME}" --release-suffix "<<parameters.release-suffix>>")
79-
SILTA_ENVIRONMENT_NAME=$(silta ci release environmentname --branchname "${BRANCHNAME}" --release-suffix "<<parameters.release-suffix>>")
80-
81-
echo "export RELEASE_NAME='$RELEASE_NAME'" >> "$BASH_ENV"
82-
echo "export NAMESPACE='$NAMESPACE'" >> "$BASH_ENV"
83-
echo "export SILTA_ENVIRONMENT_NAME='$SILTA_ENVIRONMENT_NAME'" >> "$BASH_ENV"
84-
85-
echo "The release name for this branch is \"$RELEASE_NAME\" in the \"$NAMESPACE\" namespace"
86-
docker_build_nginx: |
87-
echo "Build nginx"
88-
NAMESPACE="${CIRCLE_PROJECT_REPONAME,,}"
89-
BRANCHNAME="${CIRCLE_BRANCH}"
90-
91-
IMAGE_URL=$(silta ci image url \
92-
--image-repo-host "${DOCKER_REPO_HOST}" \
93-
--image-repo-project "${DOCKER_REPO_PROJ}" \
94-
--namespace "${NAMESPACE}" \
95-
--image-identifier "nginx" \
96-
--build-path "" \
97-
--dockerfile "nginx.Dockerfile" \
98-
--image-tag "" \
99-
--image-tag-prefix "v1" \
100-
)
101-
102-
if [ '<<parameters.expose_image>>' = 'true' ]; then
103-
# Persist the image identifier and tag so it is available during deployment.
104-
echo "export nginx_IMAGE_IDENTIFIER='nginx'" >> "$BASH_ENV"
105-
echo "export nginx_IMAGE_URL='${IMAGE_URL}'" >> "$BASH_ENV"
106-
fi
107-
108-
# Create temporary file for storing build process exit code with "build_process" prefix.
109-
exit_code_file=$(mktemp /tmp/build-docker-image.XXXXXX)
110-
touch $exit_code_file
111-
112-
# Trap and store exit code of the build process.
113-
trap 'echo $? > $exit_code_file' EXIT
114-
115-
# Build the docker image.
116-
silta ci image build \
117-
--image-repo-host "${DOCKER_REPO_HOST}" \
118-
--image-repo-project "${DOCKER_REPO_PROJ}" \
119-
--namespace "${NAMESPACE}" \
120-
--image-identifier "nginx" \
121-
--build-path "<<parameters.path>>" \
122-
--dockerfile "<<parameters.dockerfile>>" \
123-
--image-tag-prefix "<<parameters.docker-hash-prefix>>" \
124-
--image-tag "<<parameters.tag>>" \
125-
--branchname "${BRANCHNAME}" \
126-
--image-reuse <<parameters.reuse_image>>
127-
128-
129-
.filter_feature_only:
130-
rules:
131-
- if: $CI_COMMIT_BRANCH == "production"
132-
when: never
133-
- if: $CI_COMMIT_BRANCH == "master"
134-
when: never
135-
- if: $CI_COMMIT_BRANCH =~ /feature\/test-cluster(\/.*)?/
136-
when: never
137-
- if: $CI_COMMIT_BRANCH =~ /feature\/aws-cluster(\/.*)?/
138-
when: never
139-
- if: $CI_COMMIT_BRANCH =~ /feature\/aks-cluster(\/.*)?/
140-
when: never
141-
- when: on_success
142-
143-
default:
144-
image: wunderio/silta-cicd:circleci-php8.3-node22-composer2-v1
1451

1462
stages:
1473
- build
1484

1495
include:
150-
- component: $CI_SERVER_FQDN/root/test-components-1/setup-silta-cli@main
151-
inputs:
152-
silta-cli-version: 'latest'
1536
- local: '/.gitlab/templates/drupal-build.yml'
1547

1558
drupal-build:
@@ -161,25 +14,3 @@ drupal-build:
16114
script:
16215
- echo "Project-specific build steps here..."
16316

164-
165-
build-job0:
166-
stage: build
167-
script: |
168-
echo "Hello!"
169-
170-
build-job1:
171-
stage: build
172-
script:
173-
- !reference [.commands, setup_silta_cli]
174-
- !reference [.commands, drupal_composer_install]
175-
- !reference [.commands, npm_install_build]
176-
- !reference [.commands, setup_silta_proxy]
177-
- !reference [.commands, cloud_login]
178-
- silta ci release list --namespace gitlab
179-
- silta ci release list --namespace drupal-project-k8s
180-
#- !reference [.commands, docker_login]
181-
#- !reference [.commands, set_release_name]
182-
#- !reference [.commands, docker_build_nginx]
183-
rules:
184-
- !reference [.filter_feature_only, rules]
185-

.gitlab/templates/drupal-build.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

2-
.decrypt-files: &decrypt-files
3-
- echo "Decrypting files: $DECRYPT_FILES..."
2+
.decrypt-files:
3+
command: |
4+
echo "Decrypting files: $DECRYPT_FILES..."
45
56
.docker-setup: &docker-setup
67
- echo "Setting up Docker version: $DOCKER_VERSION..."
@@ -27,5 +28,5 @@ include:
2728
DECRYPT_FILES: "n/a"
2829
DOCKER_VERSION: "v1"
2930
before_script:
30-
- *decrypt-files
31+
- !reference [.decrypt-files, command]
3132
- echo "additional before_script command"

0 commit comments

Comments
 (0)