CN114356424A - Method for sharing mirror image by multiple environments of front-end project and computer readable storage medium - Google Patents
Method for sharing mirror image by multiple environments of front-end project and computer readable storage medium Download PDFInfo
- Publication number
- CN114356424A CN114356424A CN202111566893.2A CN202111566893A CN114356424A CN 114356424 A CN114356424 A CN 114356424A CN 202111566893 A CN202111566893 A CN 202111566893A CN 114356424 A CN114356424 A CN 114356424A
- Authority
- CN
- China
- Prior art keywords
- mirror image
- project
- environment
- static file
- file
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/4401—Bootstrapping
- G06F9/4406—Loading of operating system
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44505—Configuring for program initiating, e.g. using registry, configuration files
- G06F9/4451—User profiles; Roaming
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computer Security & Cryptography (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The embodiment of the invention discloses a method for sharing a mirror image by multiple environments of a front-end project, which comprises the following steps: when the front-end project code needs to refer to the rear-end interface address, inserting a placeholder to replace the real rear-end interface address, and performing front-end compiling based on the set code to obtain a front-end static file; constructing a front-end mirror image based on the front-end static file and the customized start script; pushing the constructed front-end mirror image to a central mirror image warehouse; when the front-end project is deployed in a multi-set kubernets cluster environment, the same front-end mirror image is pulled from a central mirror image warehouse; the kubernets deployment file of the front-end project refers to a customized start script through an instruction, and an API-URL environment variable is added for dynamically transmitting a back-end interface address; the customized start script receives an API-URL environment variable transmitted in the deployment file, executes change operation, and modifies a placeholder in the static file into a value of the transmitted environment variable; and starting front-end service based on the modified front-end static file in the front-end mirror image.
Description
Technical Field
The invention belongs to the technical field of software, and particularly relates to a method for sharing a mirror image by multiple environments of a front-end project and a computer-readable storage medium.
Background
With the popularity of cloud-based technologies, more and more enterprises use kubernets to deploy projects. Then, due to the complex business of the enterprise, multiple sets of technical environments, such as developing a kubernets environment, testing the kubernets environment, producing the kubernets environment, are often required to be prepared, so that a new problem is derived. kubernets is an open source for managing containerized applications on multiple hosts in a cloud platform.
Because the front-end project needs to determine the rear-end interface address in the code when compiling, the existence of multiple sets of technologies causes that one rear-end service needs multiple interface addresses to correspond to multiple sets of technical environments. For example, the address of the backend service interface of the development environment is dev-api.com, the address of the backend service interface needs to be written as dev-api.com in the code when the front-end project is deployed to the development environment. And the back-end service address of the test environment is test-api.com, when the front-end project needs to be deployed to the test environment, the code needs to be modified and recompiled. As enterprise technology environments become more and more, it takes a lot of time and server resources to modify the backend interface address in the code and recompile it each time a different environment is deployed.
Disclosure of Invention
The technical problem to be solved by the invention is to provide a method for sharing a mirror image by multiple environments of a front-end project and a computer readable storage medium, so that the front-end project is compiled once, and a back-end service interface address can be dynamically transmitted when the front-end project is deployed in each technical environment, thereby realizing multiplexing of multiple technical environments, and saving time and server resource cost.
In order to solve the technical problems, the invention adopts the following technical scheme:
in a first aspect, an embodiment of the present invention provides a method for sharing a mirror image among environments of a front-end project, including:
when the front-end project code needs to refer to the rear-end interface address, inserting a placeholder to replace the real rear-end interface address, and performing front-end compiling based on the set code to obtain a front-end static file;
constructing a front-end mirror image based on the front-end static file and the customized start script;
pushing the constructed front-end mirror image to a central mirror image warehouse;
when the front-end project is deployed in a multi-set kubernets cluster environment, the same front-end mirror image is pulled from a central mirror image warehouse;
the kubernets deployment file of the front-end project refers to a customized start script through an instruction, and an API-URL environment variable is added for dynamically transmitting a back-end interface address;
the customized start script receives an API-URL environment variable transmitted in the deployment file, executes change operation, and modifies a placeholder in the static file into a value of the transmitted environment variable;
and starting front-end service based on the modified front-end static file in the front-end mirror image.
In one possible design of the first aspect, constructing the front-end image based on the front-end static file and the customized start-up script includes: constructing a base image using nginx; constructing a front-end static file and a specific start script into a mirror image by using a dockerfile; and packaging the mirror image starting script through a dockerfile CMD instruction.
In a possible design of the first aspect, pushing the built front-end mirror image to the central mirror repository includes: marking a specific label on the front end mirror image through a docker tag; connecting to a central mirror repository through instructions; and pushing the mirror image to a central mirror image warehouse.
In a second aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, the program being executed by a processor to implement the method for environment-shared mirroring of front-end projects as described above.
The invention has the following beneficial effects:
(1) and the placeholder is used for replacing the rear-end interface address of different environments, so that hard codes in the codes are reduced, and the project codes are easier to maintain.
(2) Based on the customized start script, the front-end project only needs to be compiled once, so that the time cost and the server resources are saved.
(3) By dynamically injecting the rear-end interface address during deployment, multiple sets of environment multiplexing based on the same mirror image can be realized, and the problems caused by environment difference are reduced.
Drawings
FIG. 1 is a flowchart illustrating a method for sharing images among multiple environments in a front-end project according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a flowchart illustrating steps of a method for environment-shared mirroring of a front-end project according to an embodiment of the present invention is shown, including:
s10, when the front-end project code needs to refer to the rear-end interface address, inserting a placeholder to replace the real rear-end interface address, and performing front-end compiling based on the setting code to obtain a front-end static file;
s20, constructing a front-end mirror image based on the front-end static file and the customized start script;
s30, pushing the constructed front-end mirror image to a central mirror image warehouse;
s40, pulling the same front-end mirror image from a central mirror image warehouse when the front-end project is deployed in a multi-set kubernets cluster environment;
s50, the kubernets deployment file of the front-end project refers to the customized start script through an instruction, and an API-URL environment variable is added for dynamically transmitting a back-end interface address;
s60, the customized start script receives the API-URL environment variable transmitted in the deployment file, and executes the change operation, and modifies the placeholder in the static file into the value of the transmitted environment variable;
and S70, starting the front-end service based on the modified front-end static file in the front-end mirror image.
By the method for sharing the mirror image by the front-end project multi-environment, the placeholder is used for replacing rear-end interface addresses of different environments, hard codes in the codes are reduced, and project codes are easier to maintain. Meanwhile, time cost can be saved, the compiling of the front-end project is time-consuming, and the technical scheme of the embodiment of the invention only needs to be compiled once no matter how many environments exist.
In the method for sharing a mirror image among multiple environments of a front-end project according to an embodiment of the present invention, constructing a front-end mirror image based on a front-end static file and a customized startup script includes: constructing a base image using nginx; constructing a front-end static file and a specific start script into a mirror image by using a dockerfile; and packaging the mirror image starting script through a dockerfile CMD instruction. Wherein dockerfile is a file for constructing an image, and the file describes instructions for each step of constructing the image. nginx is a web server running the front-end project. dockerfile CMD specifies the commands to be run at startup, and only the last one is in effect and can be replaced.
In the method for sharing a mirror image in a front-end project multi-environment according to an embodiment of the present invention, pushing a built front-end mirror image to a central mirror image warehouse includes: marking a specific label on the front end mirror image through a docker tag; connecting to a central mirror repository through instructions; and pushing the mirror image to a central mirror image warehouse.
It will be understood by those skilled in the art that all or part of the steps of the methods of the above embodiments may be performed by instructions or by associated hardware controlled by the instructions, which may be stored in a computer readable storage medium and loaded and executed by a processor.
To this end, the present application provides a computer-readable storage medium, in which a plurality of computer programs are stored, where the computer programs can be loaded by a processor to execute the steps in any of the methods for front-end-item multi-environment shared mirroring provided by the present application. For example, the computer program may perform the steps of:
when the front-end project code needs to refer to the rear-end interface address, inserting a placeholder to replace the real rear-end interface address, and performing front-end compiling based on the set code to obtain a front-end static file;
constructing a front-end mirror image based on the front-end static file and the customized start script;
pushing the constructed front-end mirror image to a central mirror image warehouse;
when the front-end project is deployed in a multi-set kubernets cluster environment, the same front-end mirror image is pulled from a central mirror image warehouse;
the kubernets deployment file of the front-end project refers to a customized start script through an instruction, and an API-URL environment variable is added for dynamically transmitting a back-end interface address;
the customized start script receives an API-URL environment variable transmitted in the deployment file, executes change operation, and modifies a placeholder in the static file into a value of the transmitted environment variable;
and starting front-end service based on the modified front-end static file in the front-end mirror image.
The specific implementation of the above steps can be referred to the above embodiments, and will not be described herein again.
Wherein the computer-readable storage medium may include: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like.
Since the computer program stored in the storage medium can execute the steps in any method for sharing a mirror image among multiple environments for a front-end project provided by the embodiment of the present application, the beneficial effects that can be achieved by any method for sharing a mirror image among multiple environments for a front-end project provided by the embodiment of the present application can be achieved, which are detailed in the above-mentioned embodiments and will not be described herein again.
It is to be understood that the exemplary embodiments described herein are illustrative and not restrictive. Although one or more embodiments of the present invention have been described with reference to the accompanying drawings, it will be understood by those of ordinary skill in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present invention as defined by the following claims.
Claims (4)
1. A method for front-end project multi-environment sharing mirroring, comprising:
when the front-end project code needs to refer to the rear-end interface address, inserting a placeholder to replace the real rear-end interface address, and performing front-end compiling based on the set code to obtain a front-end static file;
constructing a front-end mirror image based on the front-end static file and the customized start script;
pushing the constructed front-end mirror image to a central mirror image warehouse;
when the front-end project is deployed in a multi-set kubernets cluster environment, the same front-end mirror image is pulled from a central mirror image warehouse;
the kubernets deployment file of the front-end project refers to a customized start script through an instruction, and an API-URL environment variable is added for dynamically transmitting a back-end interface address;
the customized start script receives an API-URL environment variable transmitted in the deployment file, executes change operation, and modifies a placeholder in the static file into a value of the transmitted environment variable;
and starting front-end service based on the modified front-end static file in the front-end mirror image.
2. The method for front-end project multi-environment shared mirroring of claim 1, wherein building a front-end mirror based on a front-end static file and a customized startup script comprises: constructing a base image using nginx; constructing a front-end static file and a specific start script into a mirror image by using a dockerfile; and packaging the mirror image starting script through a dockerfile CMD instruction.
3. The method of front-end project multi-environment shared mirroring of claim 1, wherein pushing the built front-end mirror to a central mirror repository comprises: marking a specific label on the front end mirror image through a docker tag; connecting to a central mirror repository through instructions; and pushing the mirror image to a central mirror image warehouse.
4. A computer-readable storage medium having stored thereon a computer program for execution by a processor to perform the method of implementing a front-end project multi-environment shared image of any of claims 1-3.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111566893.2A CN114356424A (en) | 2021-12-20 | 2021-12-20 | Method for sharing mirror image by multiple environments of front-end project and computer readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111566893.2A CN114356424A (en) | 2021-12-20 | 2021-12-20 | Method for sharing mirror image by multiple environments of front-end project and computer readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114356424A true CN114356424A (en) | 2022-04-15 |
Family
ID=81101049
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111566893.2A Pending CN114356424A (en) | 2021-12-20 | 2021-12-20 | Method for sharing mirror image by multiple environments of front-end project and computer readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114356424A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115048153A (en) * | 2022-06-21 | 2022-09-13 | 湖南快乐阳光互动娱乐传媒有限公司 | Processing method and device for webpage application, storage medium and electronic equipment |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103389895A (en) * | 2012-08-30 | 2013-11-13 | 爱乐活(北京)科技有限公司 | Method and system for generating front end page |
CN106469047A (en) * | 2015-08-18 | 2017-03-01 | 中兴通讯股份有限公司 | A kind of list implementation method and device |
-
2021
- 2021-12-20 CN CN202111566893.2A patent/CN114356424A/en active Pending
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103389895A (en) * | 2012-08-30 | 2013-11-13 | 爱乐活(北京)科技有限公司 | Method and system for generating front end page |
CN106469047A (en) * | 2015-08-18 | 2017-03-01 | 中兴通讯股份有限公司 | A kind of list implementation method and device |
Non-Patent Citations (2)
Title |
---|
掘金(蒸海鲜): "前端工程化系列-构建通用的前端镜像", HTTPS://WWW.QIYUANDI.COM/ZHANZHANG/ZONGHE/13208.HTML, pages 1 - 6 * |
果冻丨小布丁: "Docker 构建前端项目镜像", HTTPS://WWW.CNBLOGS.COM/JSERHUB/P/12941318.HTML, pages 1 - 2 * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115048153A (en) * | 2022-06-21 | 2022-09-13 | 湖南快乐阳光互动娱乐传媒有限公司 | Processing method and device for webpage application, storage medium and electronic equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111767092B (en) | Job execution method, apparatus, system and computer readable storage medium | |
US9942307B2 (en) | Web application script migration | |
US9092237B2 (en) | Serialization of pre-initialized objects | |
Taivalsaari et al. | Web browser as an application platform | |
CN111492347A (en) | System and method for updating containers | |
CN110532098B (en) | Method and system for providing GPU (graphics processing Unit) service | |
US8607203B1 (en) | Test automation framework using dependency injection | |
CN108089888B (en) | It is a kind of that operation method and system are applied based on file system | |
JP2021002317A (en) | Method, apparatus, device and storage medium for upgrading application | |
US9378013B2 (en) | Incremental source code analysis | |
US11467826B1 (en) | Automated extraction of isolated nodes during source code refactoring | |
US9477497B2 (en) | Methods for determining resource dependency and systems thereof | |
CN107766130B (en) | Method and device for migrating virtual machine to container | |
CN111475227B (en) | Business plug-in loading implementation method and device and terminal equipment | |
CN106095501B (en) | A kind of application dispositions method and device | |
WO2012131507A1 (en) | Running a plurality of instances of an application | |
US11442725B1 (en) | Software modernization refactoring of local calls to network calls | |
US11500628B1 (en) | Isolated code detection from application code analysis | |
US20140173564A1 (en) | Test scope determination based on code change(s) | |
US8024707B2 (en) | Facilitating self-remediation for software applications | |
US20230128866A1 (en) | Source code conversion from application program interface to policy document | |
US8904346B1 (en) | Method and system for automated load testing of web applications | |
US20170083387A1 (en) | High-performance computing framework for cloud computing environments | |
US20080141219A1 (en) | Multiple inheritance facility for java script language | |
CN112181592A (en) | Method for lightweight deployment of distributed system in private cloud environment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |