diff --git a/examples/deploy/Dockerfile b/examples/deploy/Dockerfile new file mode 100644 index 0000000..b7d5a89 --- /dev/null +++ b/examples/deploy/Dockerfile @@ -0,0 +1,8 @@ +# Get the most recent base image with the correct architecture from https://github.com/ManoManoTech/homer/pkgs/container/homer +FROM ghcr.io/manomanotech/homer:v0.3.0@sha256:ad5568ba02911beaf51633acd5bc63df8d815a07ea8953472ff9e4b7f1df4510 + +# Copy the configuration file and the plugins at the correct location +COPY config/ dist/config/ +COPY plugins/ dist/plugins/ + +CMD ["node", "dist/src/index.js"] \ No newline at end of file diff --git a/examples/deploy/README.md b/examples/deploy/README.md new file mode 100644 index 0000000..cfd4d44 --- /dev/null +++ b/examples/deploy/README.md @@ -0,0 +1,3 @@ +# Homer Deployment Example + +This is an example project of how to use the Homer open source [image](https://github.com/ManoManoTech/homer/pkgs/container/homer) to build and deploy your own version. diff --git a/examples/deploy/config/homer/projects.json b/examples/deploy/config/homer/projects.json new file mode 100644 index 0000000..454d6bc --- /dev/null +++ b/examples/deploy/config/homer/projects.json @@ -0,0 +1,12 @@ +{ + "projects": [ + { + "description": "project_example", + "notificationChannelIds": ["C0XXXXXXXXX"], + "projectId": 1234, + "releaseChannelId": "C0XXXXXXXXX", + "releaseManager": "myReleaseManager", + "releaseTagManager": "stableDateReleaseTagManager" + } + ] +} diff --git a/examples/deploy/pugins/release/myReleaseManager.js b/examples/deploy/pugins/release/myReleaseManager.js new file mode 100644 index 0000000..91478b1 --- /dev/null +++ b/examples/deploy/pugins/release/myReleaseManager.js @@ -0,0 +1,64 @@ +Object.defineProperty(exports, '__esModule', { value: true }); +const jobsToCheckBeforeRelease = ['Build Image']; +async function getReleaseStateUpdate( + { failedDeployments, state, successfulDeployments }, + deploymentHook +) { + if (deploymentHook === undefined) { + const isProductionEnvironment = successfulDeployments.some((env) => + env.startsWith('production') + ); + return isProductionEnvironment && state === 'monitoring' + ? [{ deploymentState: 'completed', environment: 'production' }] + : []; + } + const { environment, status } = deploymentHook; + if (environment.startsWith('staging')) { + switch (status) { + case 'failed': + return [{ deploymentState: 'failed', environment: 'staging' }]; + case 'running': + return [{ deploymentState: 'deploying', environment: 'staging' }]; + case 'success': + return [{ deploymentState: 'monitoring', environment: 'staging' }]; + default: + throw new Error(`Unhandled staging deployment status: ${status}`); + } + } else if (environment.startsWith('production')) { + switch (status) { + case 'failed': + return [{ deploymentState: 'failed', environment: 'production' }]; + case 'running': + return failedDeployments.length === 0 + ? [ + { deploymentState: 'completed', environment: 'staging' }, + { deploymentState: 'deploying', environment: 'production' }, + ] + : [{ deploymentState: 'deploying', environment: 'production' }]; + case 'success': + return [{ deploymentState: 'monitoring', environment: 'production' }]; + default: + throw new Error(`Unhandled production deployment status: ${status}`); + } + } + return []; +} +async function isReadyToRelease( + { projectId }, + mainBranchPipelineId, + { gitlab: { fetchPipelineJobs } } +) { + const pipelinesJobs = await fetchPipelineJobs( + projectId, + mainBranchPipelineId + ); + const buildJob = pipelinesJobs.find((job) => + jobsToCheckBeforeRelease.includes(job.name) + ); + return buildJob?.status === 'success'; +} +const myReleaseManager = { + getReleaseStateUpdate, + isReadyToRelease, +}; +exports.default = myReleaseManager;