From 33aeba9f1e7c9b1fd235b7ee037e13443850cac1 Mon Sep 17 00:00:00 2001 From: Vedran Mendelski Date: Sun, 11 Aug 2024 18:18:17 +0200 Subject: [PATCH] ci: enable static build with Jenkinsfile and flake.nix --- Dockerfile | 27 ------------ Jenkinsfile | 110 ++++++++++++++----------------------------------- flake.lock | 26 ++++++++++++ flake.nix | 31 ++++++++++++++ next.config.js | 6 ++- 5 files changed, 93 insertions(+), 107 deletions(-) delete mode 100644 Dockerfile create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 52eb739..0000000 --- a/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -FROM node:18.17.0-alpine - -WORKDIR /app - -# Listening port -ARG PORT=3000 -EXPOSE ${PORT} - -# Credentials -ARG SIMPLECAST_ACCESS_TOKEN -ARG REVALIDATE_WEBHOOK_TOKEN -ARG STRAPI_API_KEY -# Strapi URL -ARG STRAPI_API_URL -ARG STRAPI_GRAPHQL_URL -ARG NEXT_PUBLIC_ASSETS_BASE_URL - -ENV NODE_ENV=production -ENV NEXT_TELEMETRY_DISABLED=1 -ENV SOURCE_DIR=/app - -COPY . . - -RUN NODE_ENV=development yarn install -RUN yarn build - -CMD ["yarn", "start"] diff --git a/Jenkinsfile b/Jenkinsfile index 07a0e96..8819774 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,37 +1,9 @@ #!/usr/bin/env groovy -library 'status-jenkins-lib@v1.8.6' +library 'status-jenkins-lib@v1.9.4' pipeline { agent { label 'linux' } - parameters { - string( - name: 'IMAGE_TAG', - defaultValue: params.IMAGE_TAG ?: '', - description: 'Optional Docker image tag to push.' - ) - string( - name: 'STRAPI_API_URL', - description: 'URL of Strapi API', - defaultValue: params.STRAPI_API_URL ?: 'https://cms-press.logos.co/api', - ) - string( - name: 'STRAPI_GRAPHQL_URL', - description: 'URL of Strapi GraphQL API', - defaultValue: params.STRAPI_GRAPHQL_URL ?: 'https://cms-press.logos.co/graphql', - ) - string( - name: 'NEXT_PUBLIC_ASSETS_BASE_URL', - description: 'URL for public assets', - defaultValue: params.NEXT_PUBLIC_ASSETS_BASE_URL ?: 'https://cms-press.logos.co', - ) - string( - name: 'DOCKER_REGISTRY', - description: 'Docker registry ', - defaultValue: params.DOCKER_REGISTRY ?: 'harbor.status.im', - ) - } - options { disableConcurrentBuilds() /* manage how many builds we keep */ @@ -42,70 +14,50 @@ pipeline { } environment { - IMAGE_NAME = 'acid-info-private/logos-press-engine' + GIT_COMMITTER_NAME = 'status-im-auto' + GIT_COMMITTER_EMAIL = 'auto@status.im' } stages { + stage('Install') { + steps { + script { + nix.develop('yarn install') + } + } + } + stage('Build') { steps { script { - withCredentials([ - usernamePassword( - credentialsId: 'logos-press-engine-unbody-api-token', - usernameVariable: 'UNBODY_PROJECT_ID', - passwordVariable: 'UNBODY_API_KEY' - ), - string( - credentialsId: 'logos-press-engine-simplecast-token', - variable: 'SIMPLECAST_ACCESS_TOKEN' - ), - string( - credentialsId: 'logos-press-engine-webhook-token', - variable: 'REVALIDATE_WEBHOOK_TOKEN' - ), - string( - credentialsId: 'logos-press-engine-strapi-api-key', - variable: 'STRAPI_API_KEY' - ), - ]) { - image = docker.build( - "${DOCKER_REGISTRY}/${IMAGE_NAME}:${GIT_COMMIT.take(8)}", - ["--build-arg='STRAPI_API_KEY=${env.UNBODY_PROJECT_ID}'", - "--build-arg='UNBODY_API_KEY=${env.UNBODY_API_KEY}'", - "--build-arg='SIMPLECAST_ACCESS_TOKEN=${SIMPLECAST_ACCESS_TOKEN}'", - "--build-arg='REVALIDATE_WEBHOOK_TOKEN=${REVALIDATE_WEBHOOK_TOKEN}'", - "--build-arg='STRAPI_API_URL=${params.STRAPI_API_URL}'", - "--build-arg='STRAPI_GRAPHQL_URL=${params.STRAPI_GRAPHQL_URL}'", - "--build-arg='NEXT_PUBLIC_ASSETS_BASE_URL=${params.NEXT_PUBLIC_ASSETS_BASE_URL}'", - "--build-arg='STRAPI_API_KEY=${STRAPI_API_KEY}'", - "."].join(' ') + nix.develop('yarn build') + jenkins.genBuildMetaJSON('build/build.json') + } + } + } + + stage('Publish') { + steps { + sshagent(credentials: ['status-im-auto-ssh']) { + script { + nix.develop(""" + ghp-import \ + -b ${deployBranch()} \ + -c ${deployDomain()} \ + -p build + """ ) } } } } - - stage('Deploy') { - when { expression { params.IMAGE_TAG != '' } } - steps { script { - withDockerRegistry([ - credentialsId: 'harbor-acid-info-private-robot', url: 'https://${DOCKER_REGISTRY}' - ]) { - image.push(params.IMAGE_TAG) - } - } } - } } post { cleanup { cleanWs() } - always { script { - def result = currentBuild.result.toLowerCase() ?: 'unknown' - discord.send( - header: "Logos Press Engine Docker image build ${result}!", - descPrefix: "Image: [`${env.IMAGE_NAME}:${params.IMAGE_TAG}`](https://harbor.status.im/${params.IMAGE_NAME}/tags?name=${params.IMAGE_TAG})", - cred: 'logos-press-engine-discord-webhook-url', - ) - } } } } + +def isMasterBranch() { GIT_BRANCH ==~ /.*master/ } +def deployBranch() { isMasterBranch() ? 'deploy-master' : 'deploy-develop' } +def deployDomain() { isMasterBranch() ? 'press.logos.co' : 'dev-press.logos.co' } \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..d32efe8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1721548954, + "narHash": "sha256-7cCC8+Tdq1+3OPyc3+gVo9dzUNkNIQfwSDJ2HSi2u3o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63d37ccd2d178d54e7fb691d7ec76000740ea24a", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-24.05", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} \ No newline at end of file diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0541b0b --- /dev/null +++ b/flake.nix @@ -0,0 +1,31 @@ +{ + inputs = { + nixpkgs.url = "nixpkgs/nixos-24.05"; + }; + + outputs = + { self, nixpkgs }: + let + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forEachSystem = nixpkgs.lib.genAttrs supportedSystems; + pkgsFor = forEachSystem (system: import nixpkgs { inherit system; }); + in + rec { + formatter = forEachSystem (system: pkgsFor.${system}.nixpkgs-fmt); + + devShells = forEachSystem (system: { + default = pkgsFor.${system}.mkShellNoCC { + packages = with pkgsFor.${system}.buildPackages; [ + yarn # 1.22.22 + nodejs_20 # v20.15.1 + ghp-import # 2.1.0 + ]; + }; + }); + }; +} \ No newline at end of file diff --git a/next.config.js b/next.config.js index 0be4b84..9ea73d5 100644 --- a/next.config.js +++ b/next.config.js @@ -1,6 +1,10 @@ /** @type {import('next').NextConfig} */ const nextConfig = { - reactStrictMode: true, + output: 'export', + trailingSlash: true, + images: { + unoptimized: true, + }, images: { domains: [ 'localhost',