-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core/cli) add docker release stage with sensible default (#81)
* feat(core/cli) add docker release stage with sensible default Following the discussion #34, this PR implements a release stack for docker images that can be built in the repository and with that adds a sensitive default to the Pipelinit configuration file with the possibility to other 'registries' for the generated CI. The template basically looks for paths with Dockerfiles that can be built and adds metadata involving the path found and the specified version. Resolves: #80 * feat: add docker release stage e2e test
- Loading branch information
1 parent
df4ba1d
commit a2fc245
Showing
30 changed files
with
659 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { IntrospectFn } from "../../../types.ts"; | ||
|
||
export interface DockerContext { | ||
paths: Set<string>; | ||
} | ||
|
||
export const introspect: IntrospectFn<DockerContext> = async (context) => { | ||
const dockerContextPaths = new Set(); | ||
for await (const file of context.files.each("**/Dockerfile")) { | ||
const contextPath = file.path.replace( | ||
await context.filesWorkDir() + "/", | ||
"", | ||
).replace("/" + file.name, "").replace(file.name, ""); | ||
dockerContextPaths.add(contextPath); | ||
} | ||
return <DockerContext> { paths: dockerContextPaths }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { context } from "../../../tests/mod.ts"; | ||
import { assertEquals, deepMerge } from "../../../deps.ts"; | ||
import { config, StackRegistry } from "../../../../cli/src/lib/config.ts"; | ||
import { Platforms } from "../../../../cli/src/lib/platform.ts"; | ||
import { FileEntry } from "../../../types.ts"; | ||
|
||
import { introspector } from "./mod.ts"; | ||
|
||
config.platforms = <Platforms> ["github"]; | ||
|
||
const fakeContext = () => { | ||
return deepMerge( | ||
context, | ||
{ | ||
files: { | ||
// deno-lint-ignore require-await | ||
includes: async (glob: string): Promise<boolean> => { | ||
if (glob === "**/Dockerfile") { | ||
return true; | ||
} | ||
return false; | ||
}, | ||
each: async function* (glob: string): AsyncIterableIterator<FileEntry> { | ||
if (glob === "**/Dockerfile") { | ||
yield { | ||
name: "Dockerfile", | ||
path: "fake-path", | ||
}; | ||
} | ||
return; | ||
}, | ||
}, | ||
}, | ||
); | ||
}; | ||
|
||
Deno.test("Plugins > Check if Dockerfile is identified", async () => { | ||
const result = await introspector.introspect( | ||
fakeContext(), | ||
); | ||
|
||
assertEquals(result, { | ||
dockerContext: { | ||
paths: new Set(["fake-path"]), | ||
}, | ||
hasDockerImage: true, | ||
registries: { | ||
urls: [ | ||
"registry.hub.docker.com", | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
Deno.test("Plugins > Check if Dockerfile is identified and Other registry", async () => { | ||
config.registries = <StackRegistry> { docker: ["ghcr.io"] }; | ||
|
||
const result = await introspector.introspect( | ||
fakeContext(), | ||
); | ||
|
||
assertEquals(result, { | ||
dockerContext: { | ||
paths: new Set(["fake-path"]), | ||
}, | ||
hasDockerImage: true, | ||
registries: { | ||
urls: [ | ||
"ghcr.io", | ||
], | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { IntrospectFn } from "../../../types.ts"; | ||
import { config } from "../../../../cli/src/lib/config.ts"; | ||
|
||
export interface Registries { | ||
urls: string[]; | ||
} | ||
|
||
export const introspect: IntrospectFn<Registries> = async () => { | ||
const configRegistry = await config.registries?.docker; | ||
if (configRegistry) { | ||
return <Registries> { urls: configRegistry }; | ||
} | ||
return <Registries> { urls: ["registry.hub.docker.com"] }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Release new version | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*.*.*" | ||
|
||
env: | ||
GITHUB_REPOSITORY: ${{ github.repository }} | ||
|
||
jobs: | ||
release: | ||
name: Build and publish new release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set current version | ||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
- name: Set repository name | ||
run: echo "GITHUB_REPOSITORY=${GITHUB_REPOSITORY/*\/}" >> $GITHUB_ENV | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
<% it.registries.urls.forEach( function(url) { %> | ||
- name: Log in to the registry <%= url %> | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: <%= url %> | ||
username: ${{ secrets.REGISTRY_USERNAME }} | ||
password: ${{ secrets.REGISTRY_PASSWORD }} | ||
<% it.dockerContext.paths.forEach( function(path) { %> | ||
<%_ let dockerfilePath = !path ? "" : "-" + path -%> | ||
- name: Extract metadata (tags, labels) <%= path %> | ||
id: meta<%= dockerfilePath %> | ||
uses: docker/metadata-action@v3 | ||
with: | ||
tags: | | ||
type=semver,pattern={{version}},enable=true | ||
images: <%= url %>/${{ secrets.REGISTRY_ORGANIZATION }}/${{ env.GITHUB_REPOSITORY }}<%= dockerfilePath %> | ||
|
||
- name: Build and push Docker image <%= path %> | ||
uses: docker/build-push-action@v2 | ||
with: | ||
build-args: "version=${{ env.RELEASE_VERSION }}" | ||
context: ./<%= path %> | ||
push: true | ||
tags: ${{ steps.meta<%= dockerfilePath %>.outputs.tags }} | ||
labels: ${{ steps.meta<%= dockerfilePath %>.outputs.labels }} | ||
<% }) %> | ||
<% }) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ixtures/docker/docker-lint-build/expected/.github/workflows/pipelinit.docker.release.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Generated with pipelinit 0.4.0 | ||
# https://pipelinit.com/ | ||
name: Release new version | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*.*.*" | ||
|
||
env: | ||
GITHUB_REPOSITORY: ${{ github.repository }} | ||
|
||
jobs: | ||
release: | ||
name: Build and publish new release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set current version | ||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
- name: Set repository name | ||
run: echo "GITHUB_REPOSITORY=${GITHUB_REPOSITORY/*\/}" >> $GITHUB_ENV | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Log in to the registry registry.hub.docker.com | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: registry.hub.docker.com | ||
username: ${{ secrets.REGISTRY_USERNAME }} | ||
password: ${{ secrets.REGISTRY_PASSWORD }} | ||
- name: Extract metadata (tags, labels) | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
tags: | | ||
type=semver,pattern={{version}},enable=true | ||
images: registry.hub.docker.com/${{ secrets.REGISTRY_ORGANIZATION }}/${{ env.GITHUB_REPOSITORY }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
build-args: "version=${{ env.RELEASE_VERSION }}" | ||
context: ./ | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/fixtures/docker/release-docker/expected/.github/workflows/pipelinit.docker.build.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated with pipelinit 0.4.0 | ||
# https://pipelinit.com/ | ||
name: Build Docker | ||
on: | ||
pull_request: | ||
paths: | ||
- "**Dockerfile" | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build Dockerfiles | ||
run: | | ||
for dockerfile in $(find . -iname "*Dockerfile*" -o -iwholename "./Dockerfile"); do | ||
echo "Starting build for the Dockerfile $dockerfile" | ||
docker build . --file $dockerfile | ||
done | ||
shell: bash |
15 changes: 15 additions & 0 deletions
15
tests/fixtures/docker/release-docker/expected/.github/workflows/pipelinit.docker.lint.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Generated with pipelinit 0.4.0 | ||
# https://pipelinit.com/ | ||
name: Docker file Lint | ||
on: | ||
pull_request: | ||
paths: | ||
- "**Dockerfile" | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
container: hadolint/hadolint:latest-debian | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Run Hadolint on the project | ||
run: hadolint $(find . -iname "*Dockerfile*" -o -iwholename "./Dockerfile") |
Oops, something went wrong.