Skip to content

Commit 759e396

Browse files
RO-138 - new Codefresh workflows (#112)
* Create parent docker image that contains node_modules * Create build image and new workflow for building the install image and build image * Correct error, change stage 'clone' to 'install' * Try passing name of parent image as build arg to build image * Push install image to ghcr and pull in build image * Specify name of registry in install step * Remove org name from docker images, configured in codefresh registry * Don't forward arguments to bable and cp commands in react-orcus build targets * Set a memoryLimit of 256 in build.Dockerfile * Run build commands sequentially * Switch to only building webpack:production * Try just build-production * Replace npm run build with three separate build commands to reduce overhead * Revert "Run build commands sequentially" This reverts commit 3ca225f. * Add test step to new push workflow * Remove deuplicate WORKDIR definition from build.Dockerfile * Push build and test images so that they'll be cached * Use image WORKDIR in freestyle steps * Specify branch tag when pushing build and test images * Try using name of image to run entrypoint * Use apt-get instead of apt in test.Dockerfile * Try using job-name without substituion * Only COPY neccessary files in build.Dockerfile to increase cache performance * Explicity pull built test image from registry so that we can use entrypoint command * Correct typo, change 'jest.config.js' to 'jest.config.ts' in build.Dockerfile COP * Move base ffiles to project Dockerfile and copy additional files in build.Dockerfile * Move remaining base files to project Dockerfile * Try adding dummy argument to entrypoint command * Give up trying to use test entrypoint * Attempt to disable codefresh cache-busting labels * Attempt to circumvent cache-busting labels with a multistage build * Revert "Attempt to circumvent cache-busting labels with a multistage build" This reverts commit 067e5f4. * Try disabling CF cache to see if that gets rid of cache busting labels * Revert "Try disabling CF cache to see if that gets rid of cache busting labels" This reverts commit f246dbb. * Revert "Attempt to disable codefresh cache-busting labels" This reverts commit 0830875. * Try using multistage built to avoid cache busting install image * Copy from correct path from install stage, also copy node_modules * Correct error, copy node_modules directory, not contents * Copy install files from install image in test.Dockerfile * Copy files from earlier stages consistently * Don't run tests in paralell (try to reduce memory) * Format .babelrc as JSON * Use separate babel config for transpiling * Copy files from install image in same order they were added * Move individual test commands from pipeline to test.Dockerfile so that we can make them sequential * Copy packages and dist from build image in test.Dockerfile * Use apt-get instead of apt in test.Dockerfile * Add missing jest config files from install image in test.Dockerfile * Remove now uneccessary build artifacts cache * Use image WORKDIR for test step * Add disabled format check to default lint target * Add lint stage to push pipeline * Add missing lint.Dockerfile * Run lint task in ENTRYPOINT, not build in lint.Dockerfile * Convert to parallel pipeline * Manually send statuses to GitHub * Don't push status image (new one every build) * Specify correct status.Dockerfile for build-status-image step * Assign correct stages to status steps * Add build-status-image as dependency for status steps * Create working directory in status.Dockerfile * Correct path to status.Dockerfile * Move all status steps to new status stage * Set correct working directory for all status steps * Remove uneccessary apk installations in status.Dockerfile * Log axios errors to console * Exit(1) on axios errors * Improve axios error handling * Add logging to status script * Additional status logging * Make status ENTRYPOINT extendable * Correct syntax of status commands * Check for steps envvar * Improve status descriptions * Try overriding entrypoint with command to correctly interpolate variable * Switch to overriding status entrypoint so that variable is correct interpolated * Move status stage to end of UI * Don't run build same time as lint
1 parent fdfcfd2 commit 759e396

File tree

13 files changed

+410
-27
lines changed

13 files changed

+410
-27
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
dist/

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"tabWidth": 4,
77
"overrides": [
88
{
9-
"files": ["*.json", "*.yaml", "*.yml", "*.prettierrc"],
9+
"files": ["*.json", "*.yaml", "*.yml", "*.prettierrc", "*.babelrc"],
1010
"options": {
1111
"tabWidth": 2
1212
}

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:18-alpine
2+
3+
RUN apk add bash
4+
5+
RUN mkdir -p /usr/src/react-orcus
6+
7+
WORKDIR /usr/src/react-orcus
8+
9+
COPY package.json package.json
10+
COPY package-lock.json package-lock.json
11+
12+
RUN npm ci
13+
14+
COPY tools tools
15+
COPY .eslintrc.json .eslintrc.json
16+
COPY .prettierrc .prettierrc
17+
COPY babel.config.json babel.config.json
18+
COPY jest.config.ts jest.config.ts
19+
COPY jest.preset.js jest.preset.js
20+
COPY tsconfig.base.json tsconfig.base.json
21+
COPY nx.json nx.json
22+
COPY README.md README.md
23+
COPY LICENSE LICENSE

codefresh/build.Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ARG VERSION=latest
2+
FROM ghcr.io/vallerance/react-orcus:${VERSION} AS install
3+
4+
FROM node:18-alpine
5+
6+
RUN mkdir -p /usr/src/react-orcus
7+
8+
WORKDIR /usr/src/react-orcus
9+
10+
COPY --from=install /usr/src/react-orcus/package.json package.json
11+
COPY --from=install /usr/src/react-orcus/package-lock.json package-lock.json
12+
COPY --from=install /usr/src/react-orcus/node_modules node_modules
13+
14+
COPY --from=install /usr/src/react-orcus/tools tools
15+
COPY --from=install /usr/src/react-orcus/.eslintrc.json .eslintrc.json
16+
COPY --from=install /usr/src/react-orcus/.prettierrc .prettierrc
17+
COPY --from=install /usr/src/react-orcus/babel.config.json babel.config.json
18+
COPY --from=install /usr/src/react-orcus/tsconfig.base.json tsconfig.base.json
19+
COPY --from=install /usr/src/react-orcus/nx.json nx.json
20+
COPY --from=install /usr/src/react-orcus/README.md README.md
21+
COPY --from=install /usr/src/react-orcus/LICENSE LICENSE
22+
23+
COPY packages packages
24+
25+
# Codefresh can't support the memory overhead of just `npm run build`
26+
RUN npm run nx -- run react-orcus:build-tsc-babel
27+
RUN npm run nx -- run react-orcus:build-webpack:development
28+
RUN npm run nx -- run react-orcus:build-production

codefresh/lint.Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ARG VERSION=latest
2+
FROM ghcr.io/vallerance/react-orcus:${VERSION} AS install
3+
4+
FROM node:18-alpine
5+
6+
RUN mkdir -p /usr/src/react-orcus
7+
8+
WORKDIR /usr/src/react-orcus
9+
10+
COPY --from=install /usr/src/react-orcus/package.json package.json
11+
COPY --from=install /usr/src/react-orcus/package-lock.json package-lock.json
12+
COPY --from=install /usr/src/react-orcus/node_modules node_modules
13+
14+
COPY --from=install /usr/src/react-orcus/tools tools
15+
COPY --from=install /usr/src/react-orcus/.eslintrc.json .eslintrc.json
16+
COPY --from=install /usr/src/react-orcus/.prettierrc .prettierrc
17+
COPY --from=install /usr/src/react-orcus/tsconfig.base.json tsconfig.base.json
18+
COPY --from=install /usr/src/react-orcus/nx.json nx.json
19+
COPY --from=install /usr/src/react-orcus/README.md README.md
20+
COPY --from=install /usr/src/react-orcus/LICENSE LICENSE
21+
22+
COPY packages packages
23+
24+
ENTRYPOINT npm run lint

codefresh/push.yml

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
version: 1.0
2+
mode: parallel
3+
stages:
4+
- install
5+
- lint
6+
- build
7+
- test
8+
- status
9+
steps:
10+
clone:
11+
description: Cloning repository...
12+
type: git-clone
13+
stage: install
14+
repo: vallerance/react-orcus
15+
revision: ${{CF_BRANCH}}
16+
build-status-image:
17+
title: Building status util
18+
type: build
19+
stage: status
20+
image_name: react-orcus-status
21+
working_directory: ${{clone}}/codefresh
22+
dockerfile: status.Dockerfile
23+
build_arguments:
24+
- GITHUB_TOKEN=${{GITHUB_TOKEN}}
25+
- CF_BUILD_URL=${{CF_BUILD_URL}}
26+
- CF_REVISION=${{CF_REVISION}}
27+
disable_push: true
28+
when:
29+
steps:
30+
- name: clone
31+
install-pending:
32+
stage: status
33+
image: ${{build-status-image}}
34+
working_directory: IMAGE_WORK_DIR
35+
cmd:
36+
- install
37+
- pending
38+
when:
39+
steps:
40+
- name: build-status-image
41+
lint-pending:
42+
stage: status
43+
image: ${{build-status-image}}
44+
working_directory: IMAGE_WORK_DIR
45+
cmd:
46+
- lint
47+
- pending
48+
when:
49+
steps:
50+
- name: build-status-image
51+
build-pending:
52+
stage: status
53+
image: ${{build-status-image}}
54+
working_directory: IMAGE_WORK_DIR
55+
cmd:
56+
- build
57+
- pending
58+
when:
59+
steps:
60+
- name: build-status-image
61+
test-pending:
62+
stage: status
63+
image: ${{build-status-image}}
64+
working_directory: IMAGE_WORK_DIR
65+
cmd:
66+
- test
67+
- pending
68+
when:
69+
steps:
70+
- name: build-status-image
71+
install:
72+
title: Build react-orcus docker image
73+
type: build
74+
stage: install
75+
image_name: react-orcus
76+
tag: ${{CF_BRANCH_TAG_NORMALIZED}}
77+
working_directory: ${{clone}}
78+
registry: github-container-registry-vallerance
79+
when:
80+
steps:
81+
- name: clone
82+
install-status:
83+
stage: status
84+
image: ${{build-status-image}}
85+
working_directory: IMAGE_WORK_DIR
86+
commands:
87+
- node status.js install ${{steps.install.result}}
88+
when:
89+
steps:
90+
- name: build-status-image
91+
- name: install
92+
on:
93+
- finished
94+
build-lint:
95+
title: Building lint image
96+
type: build
97+
stage: lint
98+
image_name: react-orcus-lint
99+
tag: ${{CF_BRANCH_TAG_NORMALIZED}}
100+
working_directory: ${{clone}}
101+
dockerfile: codefresh/lint.Dockerfile
102+
build_arguments:
103+
- VERSION=${{CF_BRANCH_TAG_NORMALIZED}}
104+
registry: github-container-registry-vallerance
105+
when:
106+
steps:
107+
- name: install
108+
lint:
109+
title: Linting source
110+
stage: lint
111+
image: ${{build-lint}}
112+
working_directory: IMAGE_WORK_DIR
113+
when:
114+
steps:
115+
- name: build-lint
116+
lint-status:
117+
stage: status
118+
image: ${{build-status-image}}
119+
working_directory: IMAGE_WORK_DIR
120+
commands:
121+
- node status.js lint ${{steps.lint.result}}
122+
when:
123+
steps:
124+
- name: build-status-image
125+
- name: lint
126+
on:
127+
- finished
128+
build:
129+
title: Building library
130+
type: build
131+
stage: build
132+
image_name: react-orcus-build
133+
tag: ${{CF_BRANCH_TAG_NORMALIZED}}
134+
working_directory: ${{clone}}
135+
dockerfile: codefresh/build.Dockerfile
136+
build_arguments:
137+
- VERSION=${{CF_BRANCH_TAG_NORMALIZED}}
138+
registry: github-container-registry-vallerance
139+
when:
140+
steps:
141+
- name: lint
142+
build-status:
143+
stage: status
144+
image: ${{build-status-image}}
145+
working_directory: IMAGE_WORK_DIR
146+
commands:
147+
- node status.js build ${{steps.build.result}}
148+
when:
149+
steps:
150+
- name: build-status-image
151+
- name: build
152+
on:
153+
- finished
154+
build-test:
155+
title: Building test image
156+
type: build
157+
stage: test
158+
image_name: react-orcus-test
159+
tag: ${{CF_BRANCH_TAG_NORMALIZED}}
160+
working_directory: ${{clone}}
161+
dockerfile: codefresh/test.Dockerfile
162+
build_arguments:
163+
- VERSION=${{CF_BRANCH_TAG_NORMALIZED}}
164+
registry: github-container-registry-vallerance
165+
when:
166+
steps:
167+
- name: build
168+
test:
169+
title: Running tests
170+
stage: test
171+
image: ${{build-test}}
172+
working_directory: IMAGE_WORK_DIR
173+
when:
174+
steps:
175+
- name: build-test
176+
test-status:
177+
stage: status
178+
image: ${{build-status-image}}
179+
working_directory: IMAGE_WORK_DIR
180+
commands:
181+
- node status.js test ${{steps.test.result}}
182+
when:
183+
steps:
184+
- name: build-status-image
185+
- name: test
186+
on:
187+
- finished

codefresh/status.Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM node:18-alpine
2+
3+
RUN mkdir -p /usr/src/status
4+
5+
WORKDIR /usr/src/status
6+
7+
RUN npm install axios
8+
9+
COPY status.js .
10+
11+
ENTRYPOINT ["node", "status.js"]
12+
13+
ARG GITHUB_TOKEN
14+
ENV GITHUB_TOKEN=${GITHUB_TOKEN}
15+
ARG CF_REVISION
16+
ENV CF_REVISION=${CF_REVISION}
17+
ARG CF_BUILD_URL
18+
ENV CF_BUILD_URL=${CF_BUILD_URL}

codefresh/status.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const axios = require('axios');
2+
3+
const { GITHUB_TOKEN, CF_BUILD_URL, CF_REVISION, steps } = process.env;
4+
5+
console.log('Found environment: ', {
6+
GITHUB_TOKEN: ''.padStart(GITHUB_TOKEN.length, '*'),
7+
CF_BUILD_URL,
8+
CF_REVISION,
9+
steps,
10+
});
11+
console.log('Received args: ', process.argv);
12+
13+
const [stage, state] = process.argv.slice(2);
14+
15+
const capitalize = string => string.charAt(0).toUpperCase() + string.slice(1);
16+
17+
const descriptions = {
18+
pending: `${capitalize(stage)} pending`,
19+
success: `${capitalize(stage)} successful`,
20+
failure: `${capitalize(stage)} failed`,
21+
};
22+
const description = descriptions[state];
23+
24+
console.log(`Sending GitHub commit status: `, {
25+
stage,
26+
state,
27+
CF_BUILD_URL,
28+
description,
29+
CF_REVISION,
30+
});
31+
32+
axios
33+
.post(
34+
`https://api.github.com/repos/vallerance/react-orcus/statuses/${CF_REVISION}`,
35+
{
36+
state,
37+
target_url: CF_BUILD_URL,
38+
description,
39+
context: `react-orcus/push/${stage}`,
40+
},
41+
{
42+
headers: {
43+
Accept: 'application/vnd.github+json',
44+
Authorization: `Bearer ${GITHUB_TOKEN}`,
45+
'X-GitHub-Api-Version': '2022-11-28',
46+
},
47+
}
48+
)
49+
.then(response => {
50+
console.log(
51+
'Status sent successfully: ',
52+
JSON.stringify(response.data, undefined, 2)
53+
);
54+
process.exit(0);
55+
})
56+
.catch(error => {
57+
if (error.response) {
58+
// The request was made and the server responded with a status code
59+
// that falls out of the range of 2xx
60+
console.error(JSON.stringify(error.response.data, undefined, 2));
61+
console.error(error.response.status);
62+
console.error(JSON.stringify(error.response.headers, undefined, 2));
63+
} else if (error.request) {
64+
// The request was made but no response was received
65+
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
66+
// http.ClientRequest in node.js
67+
console.error(error.request);
68+
} else {
69+
// Something happened in setting up the request that triggered an Error
70+
console.error('Error', error.message);
71+
}
72+
console.error(JSON.stringify(error.config, undefined, 2));
73+
process.exit(1);
74+
});

0 commit comments

Comments
 (0)