From 1bf572e8b6404994b82649b33122ec59cdadaafe Mon Sep 17 00:00:00 2001 From: Rasseel Akasheh Date: Wed, 13 Oct 2021 12:48:28 +0200 Subject: [PATCH 01/25] adding dockerfile --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..6090d062 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +FROM node:12.9.1 +ENV NODE_ENV=production From 80c20959ec212659466a06361156b7679eb46526 Mon Sep 17 00:00:00 2001 From: Rasseel Akasheh Date: Wed, 13 Oct 2021 14:40:54 +0200 Subject: [PATCH 02/25] edited Dockerfile --- Dockerfile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Dockerfile b/Dockerfile index 6090d062..cf616656 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,11 @@ FROM node:12.9.1 ENV NODE_ENV=production +WORKDIR /app + +COPY ["package.json","package-lock.json*", "./"] + +RUN npm install --production + +COPY . . + +CMD ["node", "dist/index.js"] \ No newline at end of file From 1da789c0d804fd0c0489311a61c152576e710f9f Mon Sep 17 00:00:00 2001 From: Rasseel Akasheh Date: Wed, 13 Oct 2021 12:50:41 +0000 Subject: [PATCH 03/25] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index cf616656..703af3ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,4 @@ RUN npm install --production COPY . . -CMD ["node", "dist/index.js"] \ No newline at end of file +CMD ["node", "dist/index.js"] From 11a69d5d78d2980631ef316e3b5221a200a445e7 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Wed, 13 Oct 2021 20:59:39 +0200 Subject: [PATCH 04/25] Make Wrapper validator executable and GitLab CI ready Not all OS Projects are using GitHub and have the benefit of using GitHub Actions. With this changes the Wrapper-Validation-Action is executable on its own. It will use command line options for configuration instead of GitHub Action Inputs. Additionally a GitLab CI template was added and a Dockerfile for building a ready to use Dockerimage. --- .dockerignore | 2 ++ Dockerfile | 11 +++++++++++ README.md | 8 ++++++++ WrapperValidation.gitlab-ci.yml | 8 ++++++++ package-lock.json | 5 +++++ package.json | 2 ++ src/main.ts | 31 ++++++++++++++++++++++++++++--- 7 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 WrapperValidation.gitlab-ci.yml mode change 100644 => 100755 src/main.ts diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..73285922 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +__tests__ +.github diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..de163bee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM node:12-slim + +ENV NODE_ENV=production + +WORKDIR /app + +COPY . . + +RUN npm install && npm run-script build && npm install -g + +ENTRYPOINT [ "wrapper-validation-action"] diff --git a/README.md b/README.md index 1e7cfe5a..93300f62 100644 --- a/README.md +++ b/README.md @@ -104,3 +104,11 @@ Regardless of what you find, we still kindly request that you reach out to us an To learn more about verifying the Gradle Wrapper JAR locally, see our [guide on the topic](https://docs.gradle.org/current/userguide/gradle_wrapper.html#wrapper_checksum_verification). + + +## Usage in GitLab CI + +```yaml +include: + - remote: https://raw.githubusercontent.com/gradle/wrapper-validation-action/master/WrapperValidation.gitlab-ci.yml +``` \ No newline at end of file diff --git a/WrapperValidation.gitlab-ci.yml b/WrapperValidation.gitlab-ci.yml new file mode 100644 index 00000000..ececb3fd --- /dev/null +++ b/WrapperValidation.gitlab-ci.yml @@ -0,0 +1,8 @@ + +validate-wrapper: + stage: .pre + image: + name: + entrypoint: [""] + script: + - wrapper-validation-action \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 896aedcb..0c20aa41 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2507,6 +2507,11 @@ "delayed-stream": "~1.0.0" } }, + "commander": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-8.2.0.tgz", + "integrity": "sha512-LLKxDvHeL91/8MIyTAD5BFMNtoIwztGPMiM/7Bl8rIPmHCZXRxmSWr91h57dpOpnQ6jIUqEWdXE/uBYMfiVZDA==" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", diff --git a/package.json b/package.json index 299e6073..48b890bc 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "description": "Gradle Wrapper Validation Action", "main": "lib/main.js", + "bin": "lib/main.js", "scripts": { "build": "tsc", "format": "prettier --write **/*.ts", @@ -26,6 +27,7 @@ "license": "MIT", "dependencies": { "@actions/core": "1.4.0", + "commander": "^8.2.0", "typed-rest-client": "1.8.4", "unhomoglyph": "1.0.6" }, diff --git a/src/main.ts b/src/main.ts old mode 100644 new mode 100755 index bb1cd20a..691a113c --- a/src/main.ts +++ b/src/main.ts @@ -1,15 +1,40 @@ +#!/usr/bin/env node + import * as path from 'path' import * as core from '@actions/core' import * as validate from './validate' +import { Command } from 'commander'; export async function run(): Promise { try { + var minWrapperCount + var allowSnapshots + var allowChecksums + if(process.env.GITHUB_ACTION) { + minWrapperCount = +core.getInput('min-wrapper-count') + allowSnapshots = core.getInput('allow-snapshots') + allowChecksums = core.getInput('allow-checksums') + } else { + const program = new Command() + program + .description("Gradle Wrapper Validation") + .option('-m, --min-wrapper-count ', 'Minimum expected wrapper JAR files', '1') + .option('-s, --allow-snapshots ', 'Allow snapshot Gradle versions', 'false') + .option('-c, --allow-checksums [checksums...]', 'Allow arbitrary checksums, comma separated', '') + + program.parse(process.argv) + const options = program.opts() + minWrapperCount = +options.minWrapperCount + allowSnapshots = options.allowSnapshots + allowChecksums = options.allowChecksums + } + const result = await validate.findInvalidWrapperJars( path.resolve('.'), - +core.getInput('min-wrapper-count'), - core.getInput('allow-snapshots') === 'true', - core.getInput('allow-checksums').split(',') + minWrapperCount, + allowSnapshots === 'true', + allowChecksums.split(',') ) if (result.isValid()) { core.info(result.toDisplayString()) From db78afac8c191bb6cb36b383c5256e91237e049d Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 08:48:30 +0200 Subject: [PATCH 05/25] Using action.yml as definition for the program parameters --- package-lock.json | 12 +++++++++--- package.json | 9 +++++---- src/main.ts | 38 ++++++++++++++++++++++++++++---------- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0c20aa41..53c95640 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1731,6 +1731,12 @@ "@types/istanbul-lib-report": "*" } }, + "@types/js-yaml": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.3.tgz", + "integrity": "sha512-5t9BhoORasuF5uCPr+d5/hdB++zRFUTMIZOzbNkr+jZh3yQht4HYbRDyj9fY8n2TZT30iW9huzav73x4NikqWg==", + "dev": true + }, "@types/json-schema": { "version": "7.0.8", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.8.tgz", @@ -1738,9 +1744,9 @@ "dev": true }, "@types/node": { - "version": "12.20.16", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.16.tgz", - "integrity": "sha512-6CLxw83vQf6DKqXxMPwl8qpF8I7THFZuIwLt4TnNsumxkp1VsRZWT8txQxncT/Rl2UojTsFzWgDG4FRMwafrlA==", + "version": "12.20.33", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.33.tgz", + "integrity": "sha512-5XmYX2GECSa+CxMYaFsr2mrql71Q4EvHjKS+ox/SiwSdaASMoBIWE6UmZqFO+VX1jIcsYLStI4FFoB6V7FeIYw==", "dev": true }, "@types/prettier": { diff --git a/package.json b/package.json index 48b890bc..779ba2f4 100644 --- a/package.json +++ b/package.json @@ -32,18 +32,19 @@ "unhomoglyph": "1.0.6" }, "devDependencies": { - "@types/node": "12.20.16", + "@types/js-yaml": "^4.0.3", + "@types/node": "^12.20.33", "@typescript-eslint/parser": "4.28.4", "@vercel/ncc": "0.29.0", "eslint": "7.31.0", "eslint-plugin-github": "4.1.5", "eslint-plugin-jest": "24.4.0", + "glob-parent": ">=5.1.2", "jest": "27.0.6", - "js-yaml": "4.1.0", + "js-yaml": "^4.1.0", "nock": "13.1.1", "prettier": "2.3.2", "ts-jest": "27.0.4", - "typescript": "4.0.8", - "glob-parent": ">=5.1.2" + "typescript": "4.0.8" } } diff --git a/src/main.ts b/src/main.ts index 691a113c..303541bf 100755 --- a/src/main.ts +++ b/src/main.ts @@ -1,28 +1,33 @@ #!/usr/bin/env node import * as path from 'path' +import * as fs from 'fs' import * as core from '@actions/core' import * as validate from './validate' -import { Command } from 'commander'; +import { Command } from 'commander' +import * as jsyaml from 'js-yaml' export async function run(): Promise { try { - var minWrapperCount - var allowSnapshots - var allowChecksums - if(process.env.GITHUB_ACTION) { + let minWrapperCount + let allowSnapshots + let allowChecksums + if (process.env.GITHUB_ACTION) { minWrapperCount = +core.getInput('min-wrapper-count') allowSnapshots = core.getInput('allow-snapshots') allowChecksums = core.getInput('allow-checksums') } else { const program = new Command() + const actionYaml: Action = jsyaml.load(await fs.promises.readFile(path.resolve('action.yml'), 'utf8')) as Action + program - .description("Gradle Wrapper Validation") - .option('-m, --min-wrapper-count ', 'Minimum expected wrapper JAR files', '1') - .option('-s, --allow-snapshots ', 'Allow snapshot Gradle versions', 'false') - .option('-c, --allow-checksums [checksums...]', 'Allow arbitrary checksums, comma separated', '') - + .description(actionYaml.description) + + for (const [key, value] of Object.entries(actionYaml.inputs)) { + program.option('--' + key + ' ', value.description, value.default) + } + program.parse(process.argv) const options = program.opts() minWrapperCount = +options.minWrapperCount @@ -49,3 +54,16 @@ export async function run(): Promise { } run() + +interface Action { + name: string; + description: string; + author: string; + inputs: Map; +} + +interface Input { + description: string; + required?: boolean; + default?: string; +} \ No newline at end of file From 91993932b6c02b88ab8124285d23ba7807721a92 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 09:19:17 +0200 Subject: [PATCH 06/25] removing redundant type specifier --- Dockerfile | 2 +- WrapperValidation.gitlab-ci.yml | 2 +- package.json | 4 ++- src/main.ts | 61 ++++++++++++++++++--------------- 4 files changed, 38 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index de163bee..43cb6bdb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,4 @@ COPY . . RUN npm install && npm run-script build && npm install -g -ENTRYPOINT [ "wrapper-validation-action"] +ENTRYPOINT [ "wrapper-validation"] diff --git a/WrapperValidation.gitlab-ci.yml b/WrapperValidation.gitlab-ci.yml index ececb3fd..de667f88 100644 --- a/WrapperValidation.gitlab-ci.yml +++ b/WrapperValidation.gitlab-ci.yml @@ -5,4 +5,4 @@ validate-wrapper: name: entrypoint: [""] script: - - wrapper-validation-action \ No newline at end of file + - wrapper-validation \ No newline at end of file diff --git a/package.json b/package.json index 779ba2f4..419f151c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "private": true, "description": "Gradle Wrapper Validation Action", "main": "lib/main.js", - "bin": "lib/main.js", + "bin": { + "wrapper-validation": "lib/main.js" + }, "scripts": { "build": "tsc", "format": "prettier --write **/*.ts", diff --git a/src/main.ts b/src/main.ts index 303541bf..f8ca711e 100755 --- a/src/main.ts +++ b/src/main.ts @@ -1,32 +1,48 @@ #!/usr/bin/env node -import * as path from 'path' -import * as fs from 'fs' -import * as core from '@actions/core' +import path from 'path' +import { promises as fs } from 'fs' +import core from '@actions/core' -import * as validate from './validate' +import { findInvalidWrapperJars } from './validate' import { Command } from 'commander' -import * as jsyaml from 'js-yaml' +import jsyaml from 'js-yaml' + +interface Action { + name: string; + description: string; + author: string; + inputs: Map; +} + +interface Input { + description: string; + required?: boolean; + default?: string; +} export async function run(): Promise { try { - let minWrapperCount - let allowSnapshots - let allowChecksums + let minWrapperCount: number + let allowSnapshots: string + let allowChecksums: string + if (process.env.GITHUB_ACTION) { minWrapperCount = +core.getInput('min-wrapper-count') allowSnapshots = core.getInput('allow-snapshots') allowChecksums = core.getInput('allow-checksums') + } else { const program = new Command() - const actionYaml: Action = jsyaml.load(await fs.promises.readFile(path.resolve('action.yml'), 'utf8')) as Action + const actionYaml = jsyaml.load(await fs.readFile(path.resolve('action.yml'), 'utf8')) as Action program .description(actionYaml.description) - - for (const [key, value] of Object.entries(actionYaml.inputs)) { - program.option('--' + key + ' ', value.description, value.default) - } + .name('wrapper-validation') + + Object.entries(actionYaml.inputs).forEach(([key,value]) => { + program.option(`--${key} `, value.description, value.default) + }) program.parse(process.argv) const options = program.opts() @@ -35,10 +51,11 @@ export async function run(): Promise { allowChecksums = options.allowChecksums } - const result = await validate.findInvalidWrapperJars( + const result = await findInvalidWrapperJars( path.resolve('.'), minWrapperCount, allowSnapshots === 'true', + // --allow-snapshots , --allow-snapshots false/true allowChecksums.split(',') ) if (result.isValid()) { @@ -49,21 +66,9 @@ export async function run(): Promise { ) } } catch (error) { - core.setFailed(error.message) + if(error instanceof Error) + core.setFailed(error.message) } } run() - -interface Action { - name: string; - description: string; - author: string; - inputs: Map; -} - -interface Input { - description: string; - required?: boolean; - default?: string; -} \ No newline at end of file From 701d3cc1241f9ad2ef20e319b268ef54a9cfe6b6 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 11:12:32 +0200 Subject: [PATCH 07/25] refinements and preparing test setup --- .gitlab-ci.yml | 8 ++++++++ Dockerfile | 2 +- WrapperValidation.gitlab-ci.yml | 5 +++-- src/main.ts | 16 +++++++--------- 4 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..d9b02f4d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,8 @@ + + +include: + - local: WrapperValidation.gitlab-ci.yml + +validate-wrapper: + variables: + MIN_WRAPPER_COUNT: 10 diff --git a/Dockerfile b/Dockerfile index 43cb6bdb..2d81909b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,4 @@ COPY . . RUN npm install && npm run-script build && npm install -g -ENTRYPOINT [ "wrapper-validation"] +ENTRYPOINT [ "wrapper-validation" ] diff --git a/WrapperValidation.gitlab-ci.yml b/WrapperValidation.gitlab-ci.yml index de667f88..7856296d 100644 --- a/WrapperValidation.gitlab-ci.yml +++ b/WrapperValidation.gitlab-ci.yml @@ -2,7 +2,8 @@ validate-wrapper: stage: .pre image: - name: + name: wrapper-validation:latest entrypoint: [""] script: - - wrapper-validation \ No newline at end of file + - echo "wrapper-validation --min-wrapper-count=$MIN_WRAPPER_COUNT" + - wrapper-validation --min-wrapper-count=$MIN_WRAPPER_COUNT diff --git a/src/main.ts b/src/main.ts index f8ca711e..f898029e 100755 --- a/src/main.ts +++ b/src/main.ts @@ -2,7 +2,7 @@ import path from 'path' import { promises as fs } from 'fs' -import core from '@actions/core' +import { setFailed, getInput, info} from '@actions/core' import { findInvalidWrapperJars } from './validate' import { Command } from 'commander' @@ -28,9 +28,9 @@ export async function run(): Promise { let allowChecksums: string if (process.env.GITHUB_ACTION) { - minWrapperCount = +core.getInput('min-wrapper-count') - allowSnapshots = core.getInput('allow-snapshots') - allowChecksums = core.getInput('allow-checksums') + minWrapperCount = +getInput('min-wrapper-count') + allowSnapshots = getInput('allow-snapshots') + allowChecksums = getInput('allow-checksums') } else { const program = new Command() @@ -38,7 +38,6 @@ export async function run(): Promise { program .description(actionYaml.description) - .name('wrapper-validation') Object.entries(actionYaml.inputs).forEach(([key,value]) => { program.option(`--${key} `, value.description, value.default) @@ -55,19 +54,18 @@ export async function run(): Promise { path.resolve('.'), minWrapperCount, allowSnapshots === 'true', - // --allow-snapshots , --allow-snapshots false/true allowChecksums.split(',') ) if (result.isValid()) { - core.info(result.toDisplayString()) + info(result.toDisplayString()) } else { - core.setFailed( + setFailed( `Gradle Wrapper Validation Failed!\n See https://github.com/gradle/wrapper-validation-action#reporting-failures\n${result.toDisplayString()}` ) } } catch (error) { if(error instanceof Error) - core.setFailed(error.message) + setFailed(error.message) } } From bd9a29d1a5406a7f8a699c99efb74c4161e217fc Mon Sep 17 00:00:00 2001 From: Rasseel Akasheh Date: Thu, 14 Oct 2021 09:43:00 +0000 Subject: [PATCH 08/25] Update WrapperValidation.gitlab-ci.yml --- WrapperValidation.gitlab-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/WrapperValidation.gitlab-ci.yml b/WrapperValidation.gitlab-ci.yml index 7856296d..81ed2325 100644 --- a/WrapperValidation.gitlab-ci.yml +++ b/WrapperValidation.gitlab-ci.yml @@ -1,8 +1,7 @@ - validate-wrapper: stage: .pre image: - name: wrapper-validation:latest + name: registry.gitlab.com/netconomy/personal/r.akasheh/gradle-wrapper-validation:7ac3c97443f1f9b80d26602937e9c19bf4b6a3f2 entrypoint: [""] script: - echo "wrapper-validation --min-wrapper-count=$MIN_WRAPPER_COUNT" From 3ccbb71b33d9ec85c3267b1e3053823339d9e864 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 14:06:14 +0200 Subject: [PATCH 09/25] Make it nice executable --- .gitlab-ci.yml | 92 ++++++++++++++++++++++++++++++++- WrapperValidation.gitlab-ci.yml | 5 +- src/main.ts | 19 ++++--- 3 files changed, 104 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d9b02f4d..33c28c9e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,98 @@ + + # This is a GitLab CI configuration to build the project as a docker image +# The file is generic enough to be dropped in a project containing a working Dockerfile +# Author: Florent CHAUVEAU +# Mentioned here: https://blog.callr.tech/building-docker-images-with-gitlab-ci-best-practices/ + +# do not use "latest" here, if you want this to work in the future +image: docker:20 + +stages: + - build + - test + - push + +services: +- docker:20-dind + +# Use this if your GitLab runner does not use socket binding +# services: +# - docker:dind + +before_script: + # docker login asks for the password to be passed through stdin for security + # we use $CI_REGISTRY_PASSWORD here which is a special variable provided by GitLab + # https://docs.gitlab.com/ce/ci/variables/predefined_variables.html + - echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY + +Build: + stage: build + script: + # fetches the latest image (not failing if image is not found) + - docker pull $CI_REGISTRY_IMAGE:latest || true + # builds the project, passing proxy variables, using OCI labels + # notice the cache-from, which is going to use the image we just pulled locally + # the built image is tagged locally with the commit SHA, and then pushed to + # the GitLab registry + - > + docker build + --pull + --build-arg http_proxy=$http_proxy + --build-arg https_proxy=$https_proxy + --build-arg no_proxy=$no_proxy + --cache-from $CI_REGISTRY_IMAGE:latest + --label "org.opencontainers.image.title=$CI_PROJECT_TITLE" + --label "org.opencontainers.image.url=$CI_PROJECT_URL" + --label "org.opencontainers.image.created=$CI_JOB_STARTED_AT" + --label "org.opencontainers.image.revision=$CI_COMMIT_SHA" + --label "org.opencontainers.image.version=$CI_COMMIT_REF_NAME" + --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + . + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + include: - local: WrapperValidation.gitlab-ci.yml validate-wrapper: + stage: test + image: + name: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + entrypoint: [""] + variables: + ALLOW_CHECKSUMS: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' + +# Here, the goal is to tag the "master" branch as "latest" +Push latest: + variables: + # We are just playing with Docker here. + # We do not need GitLab to clone the source code. + GIT_STRATEGY: none + stage: push + only: + # Only "master" should be tagged "latest" + - master + script: + # Because we have no guarantee that this job will be picked up by the same runner + # that built the image in the previous step, we pull it again locally + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + # Then we tag it "latest" + - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest + # Annnd we push it. + - docker push $CI_REGISTRY_IMAGE:latest + +# Finally, the goal here is to Docker tag any Git tag +# GitLab will start a new pipeline everytime a Git tag is created, which is pretty awesome +Push tag: variables: - MIN_WRAPPER_COUNT: 10 + # Again, we do not need the source code here. Just playing with Docker. + GIT_STRATEGY: none + stage: push + only: + # We want this job to be run on tags only. + - tags + script: + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME diff --git a/WrapperValidation.gitlab-ci.yml b/WrapperValidation.gitlab-ci.yml index 81ed2325..e0840cee 100644 --- a/WrapperValidation.gitlab-ci.yml +++ b/WrapperValidation.gitlab-ci.yml @@ -1,8 +1,7 @@ validate-wrapper: stage: .pre image: - name: registry.gitlab.com/netconomy/personal/r.akasheh/gradle-wrapper-validation:7ac3c97443f1f9b80d26602937e9c19bf4b6a3f2 + name: registry.gitlab.com/netconomy/personal/r.akasheh/gradle-wrapper-validation:latest entrypoint: [""] script: - - echo "wrapper-validation --min-wrapper-count=$MIN_WRAPPER_COUNT" - - wrapper-validation --min-wrapper-count=$MIN_WRAPPER_COUNT + - wrapper-validation diff --git a/src/main.ts b/src/main.ts index f898029e..5456b746 100755 --- a/src/main.ts +++ b/src/main.ts @@ -2,10 +2,10 @@ import path from 'path' import { promises as fs } from 'fs' -import { setFailed, getInput, info} from '@actions/core' +import { setFailed, getInput, info } from '@actions/core' import { findInvalidWrapperJars } from './validate' -import { Command } from 'commander' +import { Command, Option } from 'commander' import jsyaml from 'js-yaml' interface Action { @@ -18,7 +18,7 @@ interface Action { interface Input { description: string; required?: boolean; - default?: string; + default?: string; } export async function run(): Promise { @@ -26,7 +26,7 @@ export async function run(): Promise { let minWrapperCount: number let allowSnapshots: string let allowChecksums: string - + if (process.env.GITHUB_ACTION) { minWrapperCount = +getInput('min-wrapper-count') allowSnapshots = getInput('allow-snapshots') @@ -38,9 +38,12 @@ export async function run(): Promise { program .description(actionYaml.description) - - Object.entries(actionYaml.inputs).forEach(([key,value]) => { - program.option(`--${key} `, value.description, value.default) + + Object.entries(actionYaml.inputs).forEach(([key, value]) => { + program.addOption( + new Option(`--${key} `, value.description) + .default(value.default) + .env(key.toLocaleUpperCase().replace(/-/g, '_'))) }) program.parse(process.argv) @@ -64,7 +67,7 @@ export async function run(): Promise { ) } } catch (error) { - if(error instanceof Error) + if (error instanceof Error) setFailed(error.message) } } From 9e67ca145f3b6fd23d4f40a04b9910cb8119d208 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 14:13:12 +0200 Subject: [PATCH 10/25] Removing node_env --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2d81909b..152f1add 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM node:12-slim -ENV NODE_ENV=production - WORKDIR /app COPY . . From 841abf7ef6849e7c8454ce4c5305d8ba86051e75 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 14:19:08 +0200 Subject: [PATCH 11/25] fixing build --- .gitlab-ci.yml | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 33c28c9e..c10d7192 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,28 +6,30 @@ # Author: Florent CHAUVEAU # Mentioned here: https://blog.callr.tech/building-docker-images-with-gitlab-ci-best-practices/ -# do not use "latest" here, if you want this to work in the future -image: docker:20 + stages: - build - test - push -services: -- docker:20-dind - -# Use this if your GitLab runner does not use socket binding -# services: -# - docker:dind +.docker: + # do not use "latest" here, if you want this to work in the future + image: docker:20 + services: + - docker:20-dind + # Use this if your GitLab runner does not use socket binding + # services: + # - docker:dind -before_script: - # docker login asks for the password to be passed through stdin for security - # we use $CI_REGISTRY_PASSWORD here which is a special variable provided by GitLab - # https://docs.gitlab.com/ce/ci/variables/predefined_variables.html - - echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY + before_script: + # docker login asks for the password to be passed through stdin for security + # we use $CI_REGISTRY_PASSWORD here which is a special variable provided by GitLab + # https://docs.gitlab.com/ce/ci/variables/predefined_variables.html + - echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY Build: + extends: .docker stage: build script: # fetches the latest image (not failing if image is not found) @@ -39,9 +41,6 @@ Build: - > docker build --pull - --build-arg http_proxy=$http_proxy - --build-arg https_proxy=$https_proxy - --build-arg no_proxy=$no_proxy --cache-from $CI_REGISTRY_IMAGE:latest --label "org.opencontainers.image.title=$CI_PROJECT_TITLE" --label "org.opencontainers.image.url=$CI_PROJECT_URL" @@ -65,6 +64,7 @@ validate-wrapper: # Here, the goal is to tag the "master" branch as "latest" Push latest: + extends: .docker variables: # We are just playing with Docker here. # We do not need GitLab to clone the source code. @@ -85,6 +85,7 @@ Push latest: # Finally, the goal here is to Docker tag any Git tag # GitLab will start a new pipeline everytime a Git tag is created, which is pretty awesome Push tag: + extends: .docker variables: # Again, we do not need the source code here. Just playing with Docker. GIT_STRATEGY: none From 1d5211f70bab789e4ccc902c5eb7f17cef8e4d45 Mon Sep 17 00:00:00 2001 From: Rasseel Akasheh Date: Thu, 14 Oct 2021 12:53:14 +0000 Subject: [PATCH 12/25] trying out action yml path --- src/main.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 5456b746..c2a16828 100755 --- a/src/main.ts +++ b/src/main.ts @@ -34,7 +34,8 @@ export async function run(): Promise { } else { const program = new Command() - const actionYaml = jsyaml.load(await fs.readFile(path.resolve('action.yml'), 'utf8')) as Action + // const actionYaml = jsyaml.load(await fs.readFile(path.resolve('action.yml'), 'utf8')) as Action + const actionYaml = jsyaml.load(await fs.readFile(path.join('_dirname','action.yml'), 'utf8')) as Action program .description(actionYaml.description) From 1e99869fef0e60030ccaed3a667997df21a415ce Mon Sep 17 00:00:00 2001 From: Rasseel Akasheh Date: Thu, 14 Oct 2021 12:57:56 +0000 Subject: [PATCH 13/25] Update main.ts --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index c2a16828..4870b74f 100755 --- a/src/main.ts +++ b/src/main.ts @@ -35,7 +35,7 @@ export async function run(): Promise { } else { const program = new Command() // const actionYaml = jsyaml.load(await fs.readFile(path.resolve('action.yml'), 'utf8')) as Action - const actionYaml = jsyaml.load(await fs.readFile(path.join('_dirname','action.yml'), 'utf8')) as Action + const actionYaml = jsyaml.load(await fs.readFile(path.join(_dirname,'action.yml'), 'utf8')) as Action program .description(actionYaml.description) From ac7d358a250eff8f61cce2bfff45ce638ba853ac Mon Sep 17 00:00:00 2001 From: Rasseel Akasheh Date: Thu, 14 Oct 2021 13:00:48 +0000 Subject: [PATCH 14/25] Update main.ts --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 4870b74f..6faf2b30 100755 --- a/src/main.ts +++ b/src/main.ts @@ -35,7 +35,7 @@ export async function run(): Promise { } else { const program = new Command() // const actionYaml = jsyaml.load(await fs.readFile(path.resolve('action.yml'), 'utf8')) as Action - const actionYaml = jsyaml.load(await fs.readFile(path.join(_dirname,'action.yml'), 'utf8')) as Action + const actionYaml = jsyaml.load(await fs.readFile(path.join(__dirname,'action.yml'), 'utf8')) as Action program .description(actionYaml.description) From 32ecb1b5f2aa4de1ba033b88d3defe0e807c4b1a Mon Sep 17 00:00:00 2001 From: Rasseel Akasheh Date: Thu, 14 Oct 2021 13:07:49 +0000 Subject: [PATCH 15/25] Update main.ts --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 6faf2b30..af5d2c71 100755 --- a/src/main.ts +++ b/src/main.ts @@ -35,7 +35,7 @@ export async function run(): Promise { } else { const program = new Command() // const actionYaml = jsyaml.load(await fs.readFile(path.resolve('action.yml'), 'utf8')) as Action - const actionYaml = jsyaml.load(await fs.readFile(path.join(__dirname,'action.yml'), 'utf8')) as Action + const actionYaml = jsyaml.load(await fs.readFile(require.resolve('action.yml'), 'utf8')) as Action program .description(actionYaml.description) From 3c1acdf7ba056298902e15a2dd829a4fa222d2da Mon Sep 17 00:00:00 2001 From: Rasseel Akasheh Date: Thu, 14 Oct 2021 13:17:01 +0000 Subject: [PATCH 16/25] Update main.ts --- src/main.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.ts b/src/main.ts index af5d2c71..4a77b37d 100755 --- a/src/main.ts +++ b/src/main.ts @@ -35,6 +35,7 @@ export async function run(): Promise { } else { const program = new Command() // const actionYaml = jsyaml.load(await fs.readFile(path.resolve('action.yml'), 'utf8')) as Action + console.log(process.cwd()) const actionYaml = jsyaml.load(await fs.readFile(require.resolve('action.yml'), 'utf8')) as Action program From 584dbedbac2ef56150c4d9eb787bb2acf89c17d5 Mon Sep 17 00:00:00 2001 From: Rasseel Akasheh Date: Thu, 14 Oct 2021 13:22:06 +0000 Subject: [PATCH 17/25] Update main.ts --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 4a77b37d..26280682 100755 --- a/src/main.ts +++ b/src/main.ts @@ -36,7 +36,7 @@ export async function run(): Promise { const program = new Command() // const actionYaml = jsyaml.load(await fs.readFile(path.resolve('action.yml'), 'utf8')) as Action console.log(process.cwd()) - const actionYaml = jsyaml.load(await fs.readFile(require.resolve('action.yml'), 'utf8')) as Action + const actionYaml = jsyaml.load(await fs.readFile('./action.yml', 'utf8')) as Action program .description(actionYaml.description) From 679d29d569976ec4a25f8c203c7216033a15cb0a Mon Sep 17 00:00:00 2001 From: Rasseel Akasheh Date: Thu, 14 Oct 2021 13:40:27 +0000 Subject: [PATCH 18/25] testing cd __tests --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c10d7192..7e82ad4c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -56,6 +56,8 @@ include: validate-wrapper: stage: test + before_script: + - cd __tests__ image: name: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA entrypoint: [""] From 50ff2807066f5e2b115c88c5528b54bfc53ee370 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 15:56:53 +0200 Subject: [PATCH 19/25] trying to add githubaction --- .github/workflows/ci.yml | 42 +++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 7 +----- WrapperValidation.gitlab-ci.yml | 2 +- src/main.ts | 8 +++---- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0bed6057..5b78257e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: # rebuild any PRs and main branch changes - master - 'releases/*' +env: + IMAGE_NAME: wrapper-validation + jobs: build: # make sure build/ci work properly runs-on: ubuntu-latest @@ -22,3 +25,42 @@ jobs: with: # to allow the invalid wrapper jar present in test data allow-checksums: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + + push: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" + + - name: Test image + run: | + npm install -g gitlab-ci-local + gitlab-ci-local --file __tests__/.gitlab-ci.yml + + - name: Log in to registry + # This is where you will update the PAT to GITHUB_TOKEN + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + if: github.event_name != 'pull_request' + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # Use Docker `latest` tag convention + [ "$VERSION" == "master" ] && VERSION=latest + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION + if: github.event_name != 'pull_request' diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e82ad4c..004a7071 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,17 +52,12 @@ Build: - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA include: - - local: WrapperValidation.gitlab-ci.yml + - local: __tests__/.gitlab-ci.yml validate-wrapper: - stage: test - before_script: - - cd __tests__ image: name: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA entrypoint: [""] - variables: - ALLOW_CHECKSUMS: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' # Here, the goal is to tag the "master" branch as "latest" Push latest: diff --git a/WrapperValidation.gitlab-ci.yml b/WrapperValidation.gitlab-ci.yml index e0840cee..5db9bc3d 100644 --- a/WrapperValidation.gitlab-ci.yml +++ b/WrapperValidation.gitlab-ci.yml @@ -1,7 +1,7 @@ validate-wrapper: stage: .pre image: - name: registry.gitlab.com/netconomy/personal/r.akasheh/gradle-wrapper-validation:latest + name: ghcr.io/aepfli/wrapper-validation:latest entrypoint: [""] script: - wrapper-validation diff --git a/src/main.ts b/src/main.ts index 26280682..491dfc92 100755 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node -import path from 'path' +import { resolve, dirname } from 'path' import { promises as fs } from 'fs' import { setFailed, getInput, info } from '@actions/core' @@ -34,9 +34,7 @@ export async function run(): Promise { } else { const program = new Command() - // const actionYaml = jsyaml.load(await fs.readFile(path.resolve('action.yml'), 'utf8')) as Action - console.log(process.cwd()) - const actionYaml = jsyaml.load(await fs.readFile('./action.yml', 'utf8')) as Action + const actionYaml = jsyaml.load(await fs.readFile(dirname(require.main?.filename ??'') + '/../action.yml', 'utf8')) as Action program .description(actionYaml.description) @@ -56,7 +54,7 @@ export async function run(): Promise { } const result = await findInvalidWrapperJars( - path.resolve('.'), + resolve('.'), minWrapperCount, allowSnapshots === 'true', allowChecksums.split(',') From 56586fb123a22d29b354bddb71e67b50531783b1 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 19:32:23 +0200 Subject: [PATCH 20/25] adding gitlab-ci file --- __tests__/.gitlab-ci.yml | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 __tests__/.gitlab-ci.yml diff --git a/__tests__/.gitlab-ci.yml b/__tests__/.gitlab-ci.yml new file mode 100644 index 00000000..5d11ceaf --- /dev/null +++ b/__tests__/.gitlab-ci.yml @@ -0,0 +1,44 @@ + + +include: + - local: WrapperValidation.gitlab-ci.yml + +.false-test: + script: + - wrapper-validation && false || true + +validate-wrapper: + image: $IMAGE_NAME + stage: test + before_script: + - cd __tests__/data/valid + +validate-wrapper-numbers: + extends: + - validate-wrapper + variables: + MIN_WRAPPER_COUNT: 1 + +.validate-wrapper-invalid: + extends: + - validate-wrapper + before_script: + - cd __tests__/data/invalid + +validate-wrapper-invalid-with-checksum: + extends: + - .validate-wrapper-invalid + variables: + ALLOW_CHECKSUMS: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + +validate-wrapper-invalid-failing: + extends: + - .validate-wrapper-invalid + - .false-test + +validate-wrapper-invalid-numbers-exceeded: + extends: + - .validate-wrapper-invalid + - .false-test + variables: + MIN_WRAPPER_COUNT: 3 From 03df99196ae3c9280a4b41302ab18a609342f9ca Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 19:42:24 +0200 Subject: [PATCH 21/25] Further Testing --- .github/workflows/ci.yml | 10 ++++++++-- __tests__/.gitlab-ci.yml | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b78257e..6cc8aef3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,10 +38,16 @@ jobs: - name: Build image run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" - - name: Test image + - name: Setting up GitLab CI run: | npm install -g gitlab-ci-local - gitlab-ci-local --file __tests__/.gitlab-ci.yml + mkdir -p .gitlab-ci-local + echo "global:" > .gitlab-ci-local/variables.yml + echo "\tIMAGE_NAME: $IMAGE_NAME" >> .gitlab-ci-local/variables.yml + + - name: Testing GitLab CI + run: | + gitlab-ci-local --file __tests__/.gitlab-ci.yml --home ./ - name: Log in to registry # This is where you will update the PAT to GITHUB_TOKEN diff --git a/__tests__/.gitlab-ci.yml b/__tests__/.gitlab-ci.yml index 5d11ceaf..cef9f70c 100644 --- a/__tests__/.gitlab-ci.yml +++ b/__tests__/.gitlab-ci.yml @@ -7,6 +7,11 @@ include: script: - wrapper-validation && false || true +job: + stage: .pre + script: + - echo "IMAGE $IMAGE_NAME" + validate-wrapper: image: $IMAGE_NAME stage: test From d44ce28c62cdaaf7b78b05baf18255c4dd637262 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 19:46:21 +0200 Subject: [PATCH 22/25] CI --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6cc8aef3..4e274ce3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,10 +44,11 @@ jobs: mkdir -p .gitlab-ci-local echo "global:" > .gitlab-ci-local/variables.yml echo "\tIMAGE_NAME: $IMAGE_NAME" >> .gitlab-ci-local/variables.yml - + - name: Testing GitLab CI run: | - gitlab-ci-local --file __tests__/.gitlab-ci.yml --home ./ + cat .gitlab-ci-local/variables.yml + gitlab-ci-local --home ./ --file __tests__/.gitlab-ci.yml - name: Log in to registry # This is where you will update the PAT to GITHUB_TOKEN From 1b1b81dc91b04c28e1e7f87129c7180aa6a3a1d3 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 19:57:11 +0200 Subject: [PATCH 23/25] trying to get tests running --- .dockerignore | 1 + __tests__/.gitlab-ci.yml | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 73285922..b536bb0d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ __tests__ .github +.gitlab-ci-local diff --git a/__tests__/.gitlab-ci.yml b/__tests__/.gitlab-ci.yml index cef9f70c..515b5d64 100644 --- a/__tests__/.gitlab-ci.yml +++ b/__tests__/.gitlab-ci.yml @@ -13,7 +13,9 @@ job: - echo "IMAGE $IMAGE_NAME" validate-wrapper: - image: $IMAGE_NAME + image: + name: $IMAGE_NAME + entrypoint: [""] stage: test before_script: - cd __tests__/data/valid From 6cef04ded7a305d6f6b6ae47eac0d4ab925fb491 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 19:59:05 +0200 Subject: [PATCH 24/25] another try --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e274ce3..ad06439d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: npm install -g gitlab-ci-local mkdir -p .gitlab-ci-local echo "global:" > .gitlab-ci-local/variables.yml - echo "\tIMAGE_NAME: $IMAGE_NAME" >> .gitlab-ci-local/variables.yml + echo " IMAGE_NAME: $IMAGE_NAME" >> .gitlab-ci-local/variables.yml - name: Testing GitLab CI run: | From 520cf8ac07e79f76636da9724e7ae5429bcaaaf0 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Thu, 14 Oct 2021 20:16:54 +0200 Subject: [PATCH 25/25] Delete .gitlab-ci.yml --- .gitlab-ci.yml | 96 -------------------------------------------------- 1 file changed, 96 deletions(-) delete mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 004a7071..00000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,96 +0,0 @@ - - - - # This is a GitLab CI configuration to build the project as a docker image -# The file is generic enough to be dropped in a project containing a working Dockerfile -# Author: Florent CHAUVEAU -# Mentioned here: https://blog.callr.tech/building-docker-images-with-gitlab-ci-best-practices/ - - - -stages: - - build - - test - - push - -.docker: - # do not use "latest" here, if you want this to work in the future - image: docker:20 - services: - - docker:20-dind - # Use this if your GitLab runner does not use socket binding - # services: - # - docker:dind - - before_script: - # docker login asks for the password to be passed through stdin for security - # we use $CI_REGISTRY_PASSWORD here which is a special variable provided by GitLab - # https://docs.gitlab.com/ce/ci/variables/predefined_variables.html - - echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY - -Build: - extends: .docker - stage: build - script: - # fetches the latest image (not failing if image is not found) - - docker pull $CI_REGISTRY_IMAGE:latest || true - # builds the project, passing proxy variables, using OCI labels - # notice the cache-from, which is going to use the image we just pulled locally - # the built image is tagged locally with the commit SHA, and then pushed to - # the GitLab registry - - > - docker build - --pull - --cache-from $CI_REGISTRY_IMAGE:latest - --label "org.opencontainers.image.title=$CI_PROJECT_TITLE" - --label "org.opencontainers.image.url=$CI_PROJECT_URL" - --label "org.opencontainers.image.created=$CI_JOB_STARTED_AT" - --label "org.opencontainers.image.revision=$CI_COMMIT_SHA" - --label "org.opencontainers.image.version=$CI_COMMIT_REF_NAME" - --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - . - - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - -include: - - local: __tests__/.gitlab-ci.yml - -validate-wrapper: - image: - name: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - entrypoint: [""] - -# Here, the goal is to tag the "master" branch as "latest" -Push latest: - extends: .docker - variables: - # We are just playing with Docker here. - # We do not need GitLab to clone the source code. - GIT_STRATEGY: none - stage: push - only: - # Only "master" should be tagged "latest" - - master - script: - # Because we have no guarantee that this job will be picked up by the same runner - # that built the image in the previous step, we pull it again locally - - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - # Then we tag it "latest" - - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest - # Annnd we push it. - - docker push $CI_REGISTRY_IMAGE:latest - -# Finally, the goal here is to Docker tag any Git tag -# GitLab will start a new pipeline everytime a Git tag is created, which is pretty awesome -Push tag: - extends: .docker - variables: - # Again, we do not need the source code here. Just playing with Docker. - GIT_STRATEGY: none - stage: push - only: - # We want this job to be run on tags only. - - tags - script: - - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME - - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME