To actually weekends only solution to this problem

Summary

Never thought of a recent mission actually is not resolved during the week, made Saturday a busy day at home, not yet complete, a flash until Sunday morning, was completed. Frankly, I have not had this experience for a long time, and was troubled by a technical problem a few days, this kind of dazed, but fortunately finally solved the problem. While you may not encounter this particular task similar to, but I still want to share the process of resolving the problem for everyone, the way to talk about how to solve technical problems.

Background problem

You need to be an open source python project company's access to micro-service system (mainly java) in. Open source project referred to below opa.
opaSome projects depend on the underlying c ++ libraries, such as openImageIO .

problem analysis

When received this task, in fact, I was pretty nervous, the time is tight, almost a week you have to complete. Combined with their own situation, to assess this task there are some challenges. Mainly

  • I have not written a few years python code, c ++, and unfamiliar.
  • Lack of experience in building complex docker image
  • No access to the python language service experience in micro systems
  • War alone, with no consultation of objects

First, I will make this task a number of dismantling and assessed under the difficulty out of 5 stars

  • Build a python development environment, you need to run from one local opaproject, develop, debug. ***
  • The opaproject transformed into a web project, providing restful interface. **
  • The service registered with the service center *
  • Provide java client for external calls *
  • build docker image, deploy the services on k8s. ***

I never thought this task actually encountered so many problems in the process of resolving

Resolution process

The opaproject transformed into a web project

This task is a difficult start evaluating index 3 stars, actually found that although there are some difficulties, but can be done using search engines, composite index 2 star, the actual time spent 1d

IDE: pycharm
环境: py2/py3
包构建: pip

There are major problems encountered

python2, python3 problems
development environment is installed Py3, opaProject is py2 project, so the use of tools converted under
python turn python3

Under had to Tucao, python3 actually incompatible syntax python2, such as print and so on. But the syntax can be found in python2 python3 ran inside, this is a little pit father
but 2-> 3 major versions, can indeed do so, and locked in, without discarding the old things, increase maintenance costs

Package version issues

This for me is to write java, python package management is simply nonsense, and with not too much to describe the shock.
Trough point

  • No project dependencies file
  • Instead of specifying the package version

But because much of the project introduced package, I do not have too tangled this point, installed on a single individual up. If it is positive children need to maintain the eight projects, python now have, there is a need of the venue and
package management tool for the

The opaproject transformed into a web project

This task is completed faster than expected, the use of flaskthe package, with the flask tutorial
actually get to spend a day

The service registered with the service center && java client to provide external calls

This problem is not the content, pure manual labor, hundreds of times a day to solve

build docker image, deploy the services on k8s

This step is a 3 star begin to evaluate, really did not expect to torment me, I spent two days have not been resolved. Get resolved before the weekend. Problems encountered 10+, with some notes recorded some

1. pip installfound no version of a package, version upgrade, then need python3, in fact, the environment is python2
https://xbuba.com/questions/56970211

Final settlement by specifying the version

pip install -i https://mirrors.aliyun.com/pypi/simple  numpy==1.16.4 

Question 2. Network

这个问题折磨的我痛不欲生,欲哭无泪。因为需要验证构建是否正确,要反复的build image,每次install 各种package, pip install 
python包,需要半小时才完成的了。在家连vpn,网络更加慢,时间更长,这让我无数次拷问自己,都2019年了,我居然还在被网络带宽困扰,人活着的意义到底是为了什么,我为什么要把我美好的人生浪费在这里。

这个问题主要通过3方面解决

- docker multi stage build 

  构建多个docker base镜像,然后from base镜像,这样可以减少image的构建时间

-  更改下载软件的地址源

   比如apt,yum的,pip 的。

- 将另外一些需要wget的包下载下来,扔到内网,访问内网地址

3.docker image constructed from
need to build a base image based on the company's internal java base image, and the python project.
A beginning for granted

FROM opa.image
FROM company.image

In fact docker can only inherit from a base, the first FROM will be ignored. It requires the use of multi-stage build, copy the contents of the previous layer to a new layer
details can be multi-stage build

4.c ++ DLL problem of

multi-stage build time, the opatime of image over content copy, perform error bin / time. Lack of c ++ libraries. c ++ libraries are needed to make the kernel directly copy the file to no avail.

5.ubuntu, centos question
the company's image is based on centos system, based on ubuntu, and some are not compatible syntax open source.

Ultimate solution

My biggest problem plagued the problem is to build a docker image problem, how is based on two base image, allow to build a c ++, python, java's docker container. Solve the last problem comes from the wake of a flash.
Project requires environmental roughly as shown below

I have been entangled in the early issues

  • ubuntu,centos
  • Various packages install error problem
  • Package version of the problem
  • c++ 库make install
  • Network download problem

So many questions are intertwined, the mind is not clear.
My biggest problem plagued the problem is to build a docker image problem, how is based on two base image, allow to build a c ++, python, java's docker container. Solve the last problem comes from the wake of a flash.

因为对于我,主要难点是在于原有项目的docker image构建,而公司里面的镜像和这次新加的代码,主要就是java运行时环境,
jar 包的run,以及pip install 几个python包,这些都比较简单。

所以换了一个思路,不再基于公司的image的centos环境,而是基于opa的image,这样可以不动原来的image。相当于把那些我不熟悉的东西全都屏蔽了。

构建一个base image

FROM company.image AS builder
// 将环境基于原来的image
FROM base.image
// copy java环境到image
COPY --from=builder         /usr/lib/jvm/jdk1.8.0_172 /usr/lib/jvm/jdk1.8.0_172

然后在base image基础上构建python环境。最后问题解决。

总结

在解决这个问题的过程中,我总结一个一些基本的原则,可能会帮助到你解决问题

  1. 了解自己的技术水平,把握节奏

    在开始解决任务时,评估好难点,在解决过程中不断与预估时间对比,超出了预期,需要及时调整,
    牢牢掌握住任务的节奏,确保一切都在可控之中。
  2. 分清问题主次
    对问题分类,区分出来哪些是必须要解决的,哪些是可以忽略的。

    你可能会遇到很多问题,这些问题深究下去又会引发很多的问题,如此深度遍历,会导致任务延期,有深深的挫败感。
    只解决必须解决的问题,不是必须的但是你有兴趣的问题,记录下来,后续深究。
  3. 分而治之
    你解决的任务可能别人都没做过,网络上也找不到答案。需要将任务拆散,将有很多背景的复杂问题抽象出来,简单化,去咨询有过相关经验的人,可以使得沟通更有效率,解决问题的速度更快

关注公众号【方丈的寺院】,第一时间收到文章的更新,与方丈一起开始技术修行之路

在这里插入图片描述

参考

https://xbuba.com/questions/56970211

https://docs.docker.com/develop/develop-images/multistage-build/

https://docs.python.org/zh-cn/3.7/library/2to3.html#

Guess you like

Origin www.cnblogs.com/stoneFang/p/11768385.html