crear plugins de
semantic-release
![](https://i.imgur.com/T221NrN.png)
¿que es semantic-release?
Es una librería que permite, mediante plugins, automatizar los release de un proyecto.
¿Plugins?
- Permite integrar servicios de despliegue dentro del flujo de trabajo de semantic-release.
- Permite modificar ciertos archivos en función de la versión lanzada.
- En resumen actuar en función de determinados cambios de versión.
const AggregateError = require('aggregate-error')
const getError = require('./get-error')
const dockerLogin = require('./dockerLogin')
const getAuth = require('./getAuth')
module.exports = async (pluginConfig, ctx) => {
const errors = []
if (!pluginConfig.baseImageName) {
errors.push(getError('ENOBASEIMAGENAME', ctx))
}
if (!pluginConfig.registries || pluginConfig.registries.length === 0) {
errors.push(getError('ENOREGISTRY', ctx))
} else {
for (const { user, password, url, imageName } of pluginConfig.registries) {
try {
getAuth(user, password, url, imageName, ctx)
await dockerLogin(ctx.env[user], ctx.env[password], url)
} catch (err) {
if (err instanceof AggregateError) {
for (const individualError of err) {
errors.push(individualError)
}
} else {
errors.push(getError('EDOCKERLOGIN', ctx))
}
}
}
}
if (errors.length > 0) {
throw new AggregateError(errors)
}
}
Verificación
const AggregateError = require('aggregate-error')
const Dockerode = require('dockerode')
const getError = require('./get-error')
module.exports = async (pluginConfig, ctx) => {
try {
const docker = new Dockerode()
const image = docker.getImage(pluginConfig.baseImageName)
const tags = [ctx.nextRelease.version]
if (pluginConfig.additionalTags && pluginConfig.additionalTags.length > 0) {
tags.push(...pluginConfig.additionalTags)
}
for (const tag of tags) {
ctx.logger.log(
`Tagging docker image ${pluginConfig.baseImageName}:latest to ${pluginConfig.baseImageName}:${tag}`
)
await image.tag({ repo: pluginConfig.baseImageName, tag })
}
for (const { imageName } of pluginConfig.registries) {
for (const tag of [...tags, 'latest']) {
ctx.logger.log(
`Tagging docker image ${pluginConfig.baseImageName}:latest to ${imageName}:${tag}`
)
await image.tag({ repo: imageName, tag })
}
}
} catch (err) {
throw new AggregateError([getError('EDOCKERIMAGETAG', ctx)])
}
}
Preparación
const AggregateError = require('aggregate-error')
const Dockerode = require('dockerode')
const getError = require('./get-error')
const getAuth = require('./getAuth')
module.exports = async (pluginConfig, ctx) => {
try {
const docker = new Dockerode()
const tags = ['latest', ctx.nextRelease.version]
if (pluginConfig.additionalTags && pluginConfig.additionalTags.length > 0) {
tags.push(...pluginConfig.additionalTags)
}
for (const registry of pluginConfig.registries) {
const { user, password, url, imageName } = getAuth(
registry.user,
registry.password,
registry.url,
registry.imageName,
ctx
)
const image = docker.getImage(imageName)
const options = {
password: password,
serveraddress: url,
username: user
}
for (const tag of tags) {
ctx.logger.log(`Pushing docker image ${imageName}:${tag}`)
const response = await image.push({ tag, ...options })
await pushImage(response)
}
}
} catch (err) {
throw new AggregateError([getError('EDOCKERIMAGEPUSH', ctx)])
}
}
Publicación
![](https://i.imgur.com/jd9mMjH.png)
semantic-release-sentry-releases
Permite crear release en sentry
![](https://i.imgur.com/Gox3BpY.png)
# ...
› ℹ Start step "verifyConditions" of plugin "@eclass/semantic-release-docker"
› ✔ Completed step "verifyConditions" of plugin "@eclass/semantic-release-docker"
› ℹ Start step "prepare" of plugin "@eclass/semantic-release-docker"
› ℹ Tagging docker image registry.gitlab.com/my-group/my-app:latest to registry.gitlab.com/my-group/my-app:17.36.0
› ℹ Tagging docker image registry.gitlab.com/my-group/my-app:latest to xxx.dkr.ecr.sa-east-1.amazonaws.com/my-app:17.36.0
› ℹ Tagging docker image registry.gitlab.com/my-group/my-app:latest to xxx.dkr.ecr.sa-east-1.amazonaws.com/my-app:latest
› ✔ Completed step "prepare" of plugin "@eclass/semantic-release-docker"
› ✔ Created tag v17.36.0
# ...
› ℹ Start step "publish" of plugin "@eclass/semantic-release-docker"
› ℹ Pushing docker image registry.gitlab.com/my-group/my-app:latest
› ℹ Pushing docker image registry.gitlab.com/my-group/my-app:17.36.0
› ℹ Pushing docker image xxx.dkr.ecr.sa-east-1.amazonaws.com/my-app:latest
› ℹ Pushing docker image xxx.dkr.ecr.sa-east-1.amazonaws.com/my-app:17.36.0
› ✔ Completed step "publish" of plugin "@eclass/semantic-release-docker"
# ...
semantic-release-DOCKER
Permite tagear y empujar imágenes docker a distintos registros de docker
# ...
› ℹ Start step "verifyConditions" of plugin "@eclass/semantic-release-ecs-deploy"
› ✔ Completed step "verifyConditions" of plugin "@eclass/semantic-release-ecs-deploy"
# ...
› ℹ Start step "publish" of plugin "@eclass/semantic-release-ecs-deploy"
› ℹ Deploying based on task definition: my-service
› ℹ Changed xxx.dkr.ecr.sa-east-1.amazonaws.com/my-app:17.36.0 of container "my-service-container" to: "xxx.dkr.ecr.sa-east-1.amazonaws.com/my-app:17.36.0" (was: "xxx.dkr.ecr.sa-east-1.amazonaws.com/my-app:17.35.0")
› ℹ Creating new task definition revision
› ℹ Successfully created revision: 21
› ℹ Updating service
› ℹ Successfully changed task definition to: my-service:21
› ℹ Deploying new task definition
› ℹ Deployment successful
› ✔ Completed step "publish" of plugin "@eclass/semantic-release-ecs-deploy"
# ...
semantic-release-ecs-deploy
Permite hacer deploy de servicios docker en aws fargate
Gracias
Crear plugins de semantic-release
By c778551
Crear plugins de semantic-release
Presentación para mostrar las capacidades que aporta semantic-release en el ciclo de vida de un release
- 116