Skip to content

Commit 4dfaf96

Browse files
young-yang03Young Yang
andauthored
Cloud mta build tool docker images (#997)
* new file: Dockerfile_mbtci_java11 new file: Dockerfile_mbtci_java17 new file: Dockerfile_mbtci_java8 new file: docker-compose.test.yml new file: scripts/build_image new file: scripts/publish_image new file: test/goss/README.MD new file: test/goss/goss_template.yaml modified: .circleci/config.yml modified: cmd/testdata/mta/node-js/package.json modified: go.mod modified: go.sum modified: integration/testdata/mta_assemble/node/package.json modified: integration/testdata/mta_demo/node-js/package.json modified: integration/testdata/mta_demo/node/package.json modified: internal/artifacts/testdata/mta/node-js/package.json modified: internal/exec/testdata/mta/node-js/package.json * modified: .circleci/config.yml modified: cmd/testdata/mta/node-js/package.json modified: go.mod modified: go.sum modified: integration/testdata/mta_assemble/node/package.json modified: integration/testdata/mta_demo/node-js/package.json modified: integration/testdata/mta_demo/node/package.json modified: internal/artifacts/testdata/mta/node-js/package.json modified: internal/exec/testdata/mta/node-js/package.json * revert on-pr-build and on_merge_build_test workflow * upgrad node 16 version and change workflow logic which after test success the rest step will run * modified: .circleci/config.yml Co-authored-by: Young Yang <young.yang03@sap.com>
1 parent 1e62707 commit 4dfaf96

File tree

17 files changed

+612
-38
lines changed

17 files changed

+612
-38
lines changed

.circleci/config.yml

Lines changed: 83 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Golang CircleCI 2.0 configuration
22
version: 2.1
33
jobs:
4-
54
build-node:
65
docker:
76
- image: cimg/node:lts
@@ -13,8 +12,7 @@ jobs:
1312

1413
build:
1514
docker:
16-
- image: cimg/go:1.16
17-
15+
- image: cimg/go:1.17
1816
environment:
1917
working_directory: ~/go/src/github.com/SAP/cloud-mta-build-tool
2018
steps:
@@ -67,10 +65,22 @@ jobs:
6765
command: |
6866
pip3 install --user reuse
6967
~/.local/bin/reuse lint
70-
71-
release:
68+
69+
ghpages:
70+
docker:
71+
- image: squidfunk/mkdocs-material:4.3.1
72+
working_directory: ~/go/src/github.com/SAP/cloud-mta-build-tool
73+
steps:
74+
- checkout
75+
- run:
76+
name: release to GitHub Pages
77+
command: |
78+
cd docs
79+
mkdocs gh-deploy --config-file ../docs/mkdocs.yml --remote-branch gh-pages
80+
81+
release-to-github:
7282
docker:
73-
- image: cimg/go:1.16
83+
- image: cimg/go:1.17
7484
working_directory: ~/go/src/github.com/SAP/cloud-mta-build-tool
7585
steps:
7686
- add_ssh_keys:
@@ -107,11 +117,15 @@ jobs:
107117
sed -i "/\"version\":/s/${CURR_MBT_VERSION}/${MBT_VERSION}/" ./package.json
108118
sed -i "/cli_version:/s/${CURR_MBT_VERSION}/${MBT_VERSION}/" ./configs/version.yaml
109119
sed -i "s/${CURR_MBT_VERSION}/${MBT_VERSION}/" ./VERSION
120+
sed -i "/ARG MBT_VERSION=/ s/${CURR_MBT_VERSION}/${MBT_VERSION}/" ./Dockerfile_mbtci_java8
121+
sed -i "/ARG MBT_VERSION=/ s/${CURR_MBT_VERSION}/${MBT_VERSION}/" ./Dockerfile_mbtci_java11
122+
sed -i "/ARG MBT_VERSION=/ s/${CURR_MBT_VERSION}/${MBT_VERSION}/" ./Dockerfile_mbtci_java17
123+
sed -i "s/- ${CURR_MBT_VERSION}/- ${MBT_VERSION}/" ./test/goss/goss_template.yaml
110124
sed -i "/- Cloud MTA Build Tool -/s/${CURR_MBT_VERSION}/${MBT_VERSION}/" ./README.md
111125
#Generate version file
112126
go generate -run "go run ./internal/buildtools/embed.go ./internal/buildtools/buildtools_msg.go -source=./configs/version.yaml -target=./internal/version/version_cfg.go -name=VersionConfig -package=version"
113127
#Add all updated files to commit
114-
git add ./package.json ./configs/version.yaml ./VERSION ./internal/version/version_cfg.go ./README.md
128+
git add ./package.json ./configs/version.yaml ./VERSION ./internal/version/version_cfg.go ./Dockerfile_mbtci_java8 ./Dockerfile_mbtci_java11 ./Dockerfile_mbtci_java17 ./test/goss/goss_template.yaml ./README.md
115129
git config user.email "${CLOUD_MTA_BOT_EMAIL}"
116130
git config user.name "${CLOUD_MTA_BOT_USER}"
117131
git commit --allow-empty -m "[skip ci] Bump version ${MBT_VERSION}"
@@ -127,8 +141,45 @@ jobs:
127141
git checkout master
128142
export GITHUB_TOKEN=${CLOUD_MTA_BOT_GITHUB_TOKEN}
129143
curl -sL https://git.io/goreleaser | bash
130-
131-
publish:
144+
145+
publish-to-dockerhub:
146+
docker:
147+
- image: cimg/go:1.17
148+
working_directory: ~/go/src/github.com/SAP/cloud-mta-build-tool
149+
steps:
150+
- checkout
151+
- setup_remote_docker:
152+
version: 20.10.6
153+
- run:
154+
name: build image pre-setup
155+
command: |
156+
#Make sure HEAD points to master
157+
git checkout master
158+
git fetch
159+
git rebase
160+
- run:
161+
name: "build Java 17 & Node 16 image"
162+
command: |
163+
MBT_VERSION=$(cat ./VERSION)
164+
sh $PWD/scripts/build_image 17 16.18.0 ${MBT_VERSION}
165+
- run:
166+
name: publish image
167+
command: |
168+
#Make sure HEAD points to master
169+
git checkout master
170+
git fetch
171+
git rebase
172+
MBT_VERSION=$(cat ./VERSION)
173+
echo "Image release: ${MBT_VERSION}"
174+
#Push to Docker Hub
175+
echo "$DOCKER_HUB_TOKEN" | docker login --username $DOCKER_HUB_USER --password-stdin
176+
sh $PWD/scripts/publish_image 17 16.18.0 ${MBT_VERSION} "devxci"
177+
178+
#Push to GitHub Container Registry
179+
echo "$CLOUD_MTA_BOT_GITHUB_TOKEN" | docker login "ghcr.io" --username $CLOUD_MTA_BOT_USER --password-stdin
180+
sh $PWD/scripts/publish_image 17 16.18.0 ${MBT_VERSION} "ghcr.io/sap"
181+
182+
publish-to-npm:
132183
docker:
133184
- image: cimg/node:lts
134185
working_directory: ~/repo
@@ -145,6 +196,7 @@ jobs:
145196
git fetch
146197
git rebase
147198
- run:
199+
# mbt is an unscoped package, do not need to add "--access public" option in npm publish cmd
148200
name: publish to npm
149201
command: |
150202
echo "//registry.npmjs.org/:_authToken=$CLOUD_MTA_BOT_NPM_TOKEN" > .npmrc
@@ -156,21 +208,10 @@ jobs:
156208
name: remove dummy release tag
157209
command: |
158210
git push https://github.com/SAP/cloud-mta-build-tool.git --delete release
159-
160-
ghpages:
161-
docker:
162-
- image: squidfunk/mkdocs-material:4.3.1
163-
working_directory: ~/go/src/github.com/SAP/cloud-mta-build-tool
164-
steps:
165-
- checkout
166-
- run:
167-
name: release to GitHub Pages
168-
command: |
169-
cd docs
170-
mkdocs gh-deploy --config-file ../docs/mkdocs.yml --remote-branch gh-pages
171211
172212
workflows:
173213
version: 2
214+
# when sub-branch's code is commited, this workflow will be execed
174215
on_pr_build:
175216
jobs:
176217
- build:
@@ -192,6 +233,7 @@ workflows:
192233
branches:
193234
ignore: master
194235

236+
# when master's code is commited or merged from sub-branch, this workflow will be execed
195237
on_merge_build_test:
196238
jobs:
197239
- build:
@@ -201,7 +243,7 @@ workflows:
201243
- build-node:
202244
filters:
203245
branches:
204-
ignore: master
246+
only: master
205247
- compliance:
206248
filters:
207249
branches:
@@ -213,42 +255,51 @@ workflows:
213255
branches:
214256
only: master
215257

216-
on_tag_build_test_deploy:
258+
# when a branch is taged by "release", this workflow will be execed
259+
on_tag_build_release_publish:
217260
jobs:
218261
- build:
219-
filters: # required since `release` has tag filters AND requires `build`
262+
filters:
220263
tags:
221264
only: /release/
222265
branches:
223266
ignore: /.*/
224267
- test:
225268
requires:
226269
- build
227-
filters: # required since `release` has tag filters AND requires `test`
270+
filters:
228271
tags:
229272
only: /release/
230273
branches:
231274
ignore: /.*/
232-
- release:
275+
- ghpages:
233276
requires:
234277
- test
235-
filters: # job runs on tag 'release' for no branches
278+
filters:
236279
tags:
237280
only: /release/
238281
branches:
239282
ignore: /.*/
240-
- ghpages:
283+
- release-to-github:
241284
requires:
242285
- test
243-
filters: # job runs on tag 'release' for no branches
286+
filters:
244287
tags:
245288
only: /release/
246289
branches:
247290
ignore: /.*/
248-
- publish:
291+
- publish-to-dockerhub:
249292
requires:
250-
- release
251-
filters: # job runs on tag 'release' for no branches
293+
- release-to-github
294+
filters:
295+
tags:
296+
only: /release/
297+
branches:
298+
ignore: /.*/
299+
- publish-to-npm:
300+
requires:
301+
- publish-to-dockerhub
302+
filters:
252303
tags:
253304
only: /release/
254305
branches:

Dockerfile_mbtci_java11

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
FROM sapmachine:11
2+
3+
# Build time arguments
4+
ARG MTA_USER_HOME=/home/mta
5+
ARG MBT_VERSION=1.2.18
6+
ARG GO_VERSION=1.15.6
7+
# node version as found in https://nodejs.org/dist/ e.g: "v16.15.0"
8+
ARG NODE_VERSION=NODE_VERSION_TEMPLATE
9+
ARG MAVEN_VERSION=3.6.3
10+
11+
# Environment variables
12+
ENV PYTHON /usr/bin/python3
13+
ENV M2_HOME=/opt/maven/apache-maven-${MAVEN_VERSION}
14+
ENV GOPATH /go
15+
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
16+
ENV CGO_ENABLED=0
17+
ENV GOOS=linux
18+
ENV DEBIAN_FRONTEND=noninteractive
19+
20+
ADD http://aia.pki.co.sap.com/aia/SAP%20Global%20Root%20CA.crt \
21+
/etc/ssl/certs/SAP_Global_Root_CA.crt
22+
23+
# Download required env tools
24+
RUN apt-get update && \
25+
apt-get install --yes --no-install-recommends \
26+
ca-certificates \
27+
git \
28+
curl && \
29+
30+
# Change security level as the SAP npm repo doesnt support buster new security upgrade
31+
# the default configuration for OpenSSL in Buster explicitly requires using more secure ciphers and protocols,
32+
# and the server running at http://npm.sap.com/ is running software configured to only provide insecure, older ciphers.
33+
# This causes SSL connections using OpenSSL from a Buster based installation to fail
34+
# Should be remove once SAP npm repo will patch the security level
35+
# see - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=912759
36+
sed -i -E 's/(CipherString\s*=\s*DEFAULT@SECLEVEL=)2/\11/' /etc/ssl/openssl.cnf && \
37+
38+
# install node
39+
NODE_HOME=/opt/nodejs; mkdir -p ${NODE_HOME} && \
40+
curl --fail --silent --output - "https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64.tar.gz" \
41+
| tar -xzv -f - -C "${NODE_HOME}" && \
42+
ln -s "${NODE_HOME}/node-${NODE_VERSION}-linux-x64/bin/node" /usr/local/bin/node && \
43+
ln -s "${NODE_HOME}/node-${NODE_VERSION}-linux-x64/bin/npm" /usr/local/bin/npm && \
44+
ln -s "${NODE_HOME}/node-${NODE_VERSION}-linux-x64/bin/npx" /usr/local/bin/ && \
45+
npm install --prefix /usr/local/ -g grunt-cli && \
46+
47+
# install ui5-cli temporay solution
48+
npm install --prefix /usr/local/ -g @ui5/cli && \
49+
50+
# installing Golang
51+
curl -O https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz && tar -xvf go${GO_VERSION}.linux-amd64.tar.gz && \
52+
mv go /usr/local && \
53+
mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" && \
54+
mkdir -p ${GOPATH}/src ${GOPATH}/bin && \
55+
56+
# update maven home
57+
M2_BASE="$(dirname ${M2_HOME})" && \
58+
mkdir -p "${M2_BASE}" && \
59+
curl --fail --silent --output - "https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz" \
60+
| tar -xzvf - -C "${M2_BASE}" && \
61+
ln -s "${M2_HOME}/bin/mvn" /usr/local/bin/mvn && \
62+
chmod --recursive a+w "${M2_HOME}"/conf/* && \
63+
64+
# Download MBT
65+
curl -L "https://github.com/SAP/cloud-mta-build-tool/releases/download/v${MBT_VERSION}/cloud-mta-build-tool_${MBT_VERSION}_Linux_amd64.tar.gz" | tar -zx -C /usr/local/bin && \
66+
chown root:root /usr/local/bin/mbt && \
67+
68+
# handle users permission
69+
useradd --home-dir "${MTA_USER_HOME}" \
70+
--create-home \
71+
--shell /bin/bash \
72+
--user-group \
73+
--uid 1000 \
74+
--comment 'Cloud MTA Build Tool' \
75+
--password "$(echo weUseMta |openssl passwd -1 -stdin)" mta && \
76+
# allow anybody to write into the images HOME
77+
chmod a+w "${MTA_USER_HOME}" && \
78+
79+
# Install essential build tools and python, required for building db modules
80+
apt-get install --yes --no-install-recommends \
81+
build-essential \
82+
python2.7 \
83+
python3 && \
84+
85+
# Install python 3.10
86+
#apt-get install software-properties-common && \
87+
#apt-get update && \
88+
#add-apt-repository ppa:deadsnakes/ppa && \
89+
#apt-get install python3.10 && \
90+
91+
# remove build env tools
92+
apt-get remove --purge --autoremove --yes \
93+
curl && \
94+
95+
rm -rf /var/lib/apt/lists/*
96+
97+
ENV PATH=$PATH:./node_modules/.bin HOME=${MTA_USER_HOME}
98+
WORKDIR /project
99+
USER mta

0 commit comments

Comments
 (0)