<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by nan on Medium]]></title>
        <description><![CDATA[Stories by nan on Medium]]></description>
        <link>https://medium.com/@chiangnan.lin?source=rss-6925c97d7a39------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Ey6ffxYgv48pV3jp.</url>
            <title>Stories by nan on Medium</title>
            <link>https://medium.com/@chiangnan.lin?source=rss-6925c97d7a39------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 10:17:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chiangnan.lin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[讀書小記：安靜是種 超能力]]></title>
            <link>https://medium.com/@chiangnan.lin/%E8%AE%80%E6%9B%B8%E5%B0%8F%E8%A8%98-%E5%AE%89%E9%9D%9C%E6%98%AF%E7%A8%AE-%E8%B6%85%E8%83%BD%E5%8A%9B-479401d67214?source=rss-6925c97d7a39------2</link>
            <guid isPermaLink="false">https://medium.com/p/479401d67214</guid>
            <dc:creator><![CDATA[nan]]></dc:creator>
            <pubDate>Sun, 16 Dec 2018 18:20:55 GMT</pubDate>
            <atom:updated>2018-12-16T18:25:18.665Z</atom:updated>
            <content:encoded><![CDATA[<p>斷斷續續的花了約兩個月的時間看完這本書. 這是繼 <strong>斜槓青年</strong> 最近看完的第二本. 很巧的作者都是很厲害的女生, 透過文字, 都讓我感受到溫和且蘊含滿滿活力.</p><p>身為一個內向者(寫這句話時, 讓我想到書裡作者也是常常會有類似的 murmur, 因為講某些話而感到不好意思), 雖已過了而立之年, 仍時常羨慕外向的同事或朋友們, 不論是在會議上口條清晰、掌控全場, 或是閒聊時大方開朗的 social, 逗得大家笑不攏嘴. 另外最近面對管理相關的課題亦覺得力不從心. 但當我才看了前幾頁, 就發現作者真的是一個超內向的人, 可是從事的工作內容卻又是平常我最害怕的事情. 不禁勾起巨大好奇心, 她到底是如何辦到的?!</p><p>這本書分成四個部分. Part 4 是我最有感觸的部分, 主要是在職場上用什麼樣的心態和方式處理事情, 如何與他人合作以及向上管理的部分. 當然其他部分也有很多很棒的想法, 不過因為最後面印象較深, 而且我是這時才想到要順手把那些想法寫下來. 我很喜歡作者在書中, 常常把內心的 os 寫出來, 因為那實在是太真實了, 不時的會勾起回憶, 想像自己身處在相同的場合時緊張、嘆氣、不舒服的心情.</p><p><strong>“比起有意識地要求自己跨出舒適圈, 擴大能力範圍更重要”</strong>, <strong>“有意識地保養自己、保護自己, 才是長久之道”</strong><br>內向者的能量很珍貴. 在面對社交場合等自己不熟悉的環境, 都會容易讓自己陷入疲乏的狀態. 有些人會有 ”演久了就是真的” 的想法, 強迫自己強顏歡笑, 努力表現得很外向. 短期可能會有效, 但無法持久. 就像賽車會到最後一刻, 才使出大絕招, 衝刺的能量應該留在更重要的時刻. 另一方面, 與其讓自己強迫式應環境, 試著轉換負面的想法, 用正向思考面對各種課題, 譬如抱著能夠認識更多的人, 獲得不同領域的知識等心態去參加社交場合, 也會讓自己更舒坦些. 與其用傳統刻苦耐勞的方式強迫自己進化, 不如調整心態, 用適合自己的方式, 達到更好的結果. 似乎更聰明些 :)</p><p><strong>“取得成功的過程中, 自信心和能力一樣重要”</strong><br>Self-Confident 的重要不言而喻. 透過刻意練習提升能力, 降低課題難度, 自信心亦跟著上升. 透過時常的自我提醒: 在不確定的狀態下, 我們要相信自己能夠做到, 即使需要花多點的時間.</p><p><strong>“你必須刻意去做: 不要想取悅所有人, 拋棄完美主義, 專注在行動、承受風險和快速失敗上”</strong><br>這段話暴露出我需要改進之處. 書中提到, 內向者不完全是因為怕犯錯被人看到而不敢行動, 極大部分的原因在於對完美主義的堅持. 因為要求完美而瞻前顧後, 躊躇不前. 自覺許多很好的想法, 最終都淪為美好的空談. 而拋棄完美主義, 專注在行動、承受風險和快速失敗上, 與敏捷開發的精神更是不謀而合. 真正的完美, 或許其實是由許多的嘗試、失敗、調整的迭代而來, 而非一蹴可及. 因此我應該要練習的是 <strong>“在完美、自信和工作效率間取得平衡”</strong>.</p><p>最後分享的是作者在後記想跟讀者分享的, 華頓商學院 Adam Grant 的提醒: “了解自己的個性, 但不要被束縛. <strong>越理解自己時, 越要更有意識地去突破自己的極限, 不要被外向或內向這種標籤限制自己的可能性</strong>.” 很感謝作者讓我發現原來不是只有我有這樣想法和感受, 我並不孤獨也不怪異. 更重要的是, 她將自身珍貴的經驗和想法, 透過溫和、生動的文字, 讓更多人理解, 朝更適合自己的方向前進. 我在閱讀斜槓青年時也有類似的感覺, 很溫暖、很美好. 也謝謝 Billy 買了這本書, 讓我有機會閱讀[安靜是種超能力- 張瀞仁 方舟文化].</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=479401d67214" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Application GitLab CI and Docker]]></title>
            <link>https://medium.com/@chiangnan.lin/android-application-gitlab-ci-and-docker-8739d8a11cee?source=rss-6925c97d7a39------2</link>
            <guid isPermaLink="false">https://medium.com/p/8739d8a11cee</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[gitlab]]></category>
            <dc:creator><![CDATA[nan]]></dc:creator>
            <pubDate>Sun, 08 Apr 2018 18:49:51 GMT</pubDate>
            <atom:updated>2018-04-08T18:49:51.724Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I started a new project building a new Android application. We used GitLab as git repository for a long time, but only for commit and code review. After merge to the specific branches, it will notify Jenkins to do CI. This time we’d like to give GitLab CI a try.</p><p>Below are the advantages to use GitLab CI:</p><ol><li>We don’t need to maintain the Jenkins machines ourselves. (We need to turn on machine or handle some network setting…)</li><li>In my opinion, GitLab CI has beautiful UI which looks like GitHub and better than Jenkins.</li><li>I just want to figure out how it actually works.</li></ol><p>After checked GitLab CI document, blogs, stackoverflow and discuss with my colleague <strong>WC</strong>, first version came out. We created 2 projects to achieve it:</p><ol><li><strong>Docker image builder project</strong><br>GitLab CI uses GitLab runner to do jobs. Runner runs docker image as the environment and execute the tasks we defined in <strong>.gitlab-ci.yml</strong>. Therefore, we need a docker image to build Android application, and it needs a <strong>Dockerfile</strong> describing what OS is and required libraries and tools.</li><li><strong>Application project</strong><br>Just application project. It contains the source code and .gitlab-ci.yml defining what tasks should be implemented in CI.</li></ol><p>Let’s start from image builder project. First is the .yml file. <strong>image</strong> tag indicates which docker image to use. Here my colleague <strong>WC</strong> provides me a image used to build docker image, but I don’t check the detail. (I think the basic docker image from Docker official repository should be enough.) There’s only one <strong>stage</strong>, that is, build the docker image. It will build image with <strong>tag</strong> follows <strong>-t</strong> according to the Dockerfile in current directory. And after build complete, we’ll push it to our repository for building application.</p><pre><strong>// .gitlab-ci.yml</strong><br>image: my_docker_builder</pre><pre>stages:<br>  - build</pre><pre>build-docker:<br>  stage: build<br>  tags:<br>    - xxx<br>    - ooo<br>  script:<br>    - &quot;docker build -t image_tag_of_this .&quot;<br>    - &quot;docker login -u user -p pass my_repository&quot;<br>    - &quot;docker push image_tag_of_this&quot;</pre><p>In the Dockerfile, <strong>FROM</strong> indicates the base image. There are many images stored in official repository. To build Android application, we choose <strong>openjdk:8-jdk</strong>. <strong>RUN</strong> instruction will execute any commands in a new layer on top of the current image and commit the results. We first install some tools and library needed to build application.(In fact, for libraries like lib32stdc++6 &amp; lib32z1 I don’t know its purpose in detail, they come from other blogs and solutions). Then download Android SDK tools and use the <strong>sdkmanagaer</strong> to download required SDK. The version of SDK or library depends on the need of application. Finally, I install grip for exporting README.md to html file, and it’s optional.</p><pre><strong>// Dockerfile</strong><br>FROM openjdk:8-jdk</pre><pre>RUN apt-get --quiet update --yes &amp;&amp; \<br>    apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 curl &amp;&amp; \<br>    <br>    # download Android SDK tools<br>    wget --quiet --output-document=android-sdk.zip <a href="https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip">https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip</a> &amp;&amp; \<br>    unzip android-sdk.zip -d /android_sdk &amp;&amp; \<br>    export ANDROID_HOME=/android_sdk &amp;&amp; \<br>    export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin &amp;&amp; \<br>    <br>    # install Android SDK &amp; dependencies<br>    echo y | sdkmanager &quot;platform-tools&quot; &quot;platforms;android-26&quot; &quot;build-tools;26.0.2&quot; &amp;&amp; \<br>    echo y | sdkmanager &quot;extras;android;m2repository&quot; &amp;&amp; \<br>    echo y | sdkmanager &quot;extras;google;google_play_services&quot; &amp;&amp; \<br>    echo y | sdkmanager &quot;extras;google;m2repository&quot; &amp;&amp; \<br>    <br>    # install pip for grip export README.md to html<br>    echo y | apt-get update  &amp;&amp; \<br>    echo y | apt-get install python-pip  &amp;&amp; \<br>    pip install grip</pre><p>Now let’s look at .yml in application project. First it uses the image pushed from image builder project. And there are 2 stages: <strong>build</strong> &amp; <strong>test</strong>.</p><blockquote>In GitLab CI, a complete flow is called a <strong>pipeline</strong>. It can have more than one <strong>stage</strong>. Each stage can contain more than one <strong>job</strong>. Stages executed in serial in a pipeline, and jobs executed in parallel in a stage.</blockquote><p>build stage builds application with script ./gradlew assembleDebug and let apk to be saved as artifacts which will be attached after job success. test stage runs unit test ./gradlew test and also save test result as aftifacts. To prevent GitLab disk size exceeds the limit, we set both artifacts <strong>expire_in</strong> 2 weeks. We can deploy release version to Google Play or release page to save it permanently. In additional, we use <strong>cache</strong> function to save gradle data when build stage, and pull it back in test stage to avoid downloading and installing it again.</p><pre><strong>// .gitlab-ci.yml</strong><br>image: image_tag_of_the_build_image</pre><pre>stages:<br>  - build<br>  - test</pre><pre>build:<br>  stage: build<br>  cache:<br>    key: gradle_cache<br>    paths:<br>      - .gradle/wrapper/<br>      - .gradle/caches/<br>    policy: push<br>  tags:<br>    - xxx<br>    - ooo<br>script:<br>    - ./gradlew assembleDebug<br>  artifacts:<br>    paths:<br>      - app/build/outputs/<br>    expire_in: 2 week</pre><pre>unitTest:<br>  stage: test<br>  cache:<br>    key: gradle_cache<br>    paths:<br>      - .gradle/wrapper/<br>      - .gradle/caches/<br>    policy: pull <br>  tags:<br>    - xxx<br>    - ooo<br>  script:<br>    - ./gradlew test<br>  artifacts:<br>    paths:<br>      - app/build/reports/tests<br>    expire_in: 2 week</pre><p>That’s it! Now when we push commit to remote, it will automatically run pipeline and execute the jobs.(Of course, there are many settings need set in GitLab page including runner, trigger build… But I won’t cover it now).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Boz86yI2I8kwC79Vt0nh-g.png" /><figcaption>GitLab pipeline results</figcaption></figure><p>The story is not over.</p><p>After a period of time, we found there’s a big problem in developing application. The pipeline takes too much time to run! From the above picture, it’s 19 minutes! How to achieve <strong>Fast Deliver</strong> if we need to wait almost 20 minutes in each submit… And more people join in the project, more obvious the issue will be. For example, sometimes we work on the divided functions of the same feature respectively. After finishing self tasks and completing code reviews, we still can’t get the result because it still running, even not merge to the develop branch yet!</p><p>After debug the log of GitLab runner console and compared to Jenkins’ (Jenkins only takes 2 minutes or less…), we have below conclusions:</p><ol><li>Build image size is too large, it takes much time to clone from repository to runner. Sometimes it even failed due to time out…</li><li>Each job will need download a lot of dependencies defined in build.gradle. For example, android gradle tool, Kotlin plugins, Glide, Okhttp, ….</li><li>Test job needs build application again because each runner is a new and clean environment</li></ol><p>Now, let’s try to fix it one by one.</p><p>About image size, we found Android SDK actually takes the most parts. However, openjdk:8-jdk also resides more than 700MB. As WC’s suggest <strong>openjdk:alpine</strong> is the alternative which based on the popular <strong>Alpine</strong> <strong>Linux</strong> project rather than <strong>Ubuntu</strong> is much smaller! We can use this image as a base, add the things we need in our own Dockerfile. It can save about 600MB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v_BEavEYeJGvua8Gy6xgoA.png" /><figcaption>openjdk:8-jdk vs openjdk:8-alpine</figcaption></figure><p>Because Alpine is slimmer image, we need add another libraries and tools to make sure build successfully. Here is our new Dockerfile:</p><pre>// <strong>Dockerfile</strong><br>FROM <strong>openjdk:8-alpine</strong></pre><pre>ENV BUILD_TOOLS &quot;26.0.2&quot;<br>ENV SDK_TOOLS_API &quot;26&quot;<br>ENV ANDROID_HOME &quot;/opt/sdk&quot;<br><strong>ENV GLIBC_VERSION &quot;2.27-r0&quot;</strong></pre><pre># Install required dependencies<br>RUN <strong>apk add --no-cache --virtual=.build-dependencies</strong> wget unzip ca-certificates bash &amp;&amp; \<br>    wget <a href="https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub">https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub</a> -O /etc/apk/keys/sgerrand.rsa.pub &amp;&amp; \<br>    wget <a href="https://github.com/sgerrand/alpine-pkg-glibc/releases/download/$%7BGLIBC_VERSION%7D/glibc-$%7BGLIBC_VERSION%7D.apk">https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk</a> -O /tmp/glibc.apk &amp;&amp; \<br>    wget <a href="https://github.com/sgerrand/alpine-pkg-glibc/releases/download/$%7BGLIBC_VERSION%7D/glibc-bin-$%7BGLIBC_VERSION%7D.apk">https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}.apk</a> -O /tmp/glibc-bin.apk &amp;&amp; \<br>    apk add --no-cache /tmp/glibc.apk /tmp/glibc-bin.apk &amp;&amp; \<br>    rm -rf /tmp/*</pre><pre># Download Android SDK tools<br>RUN wget <a href="http://dl.google.com/android/repository/sdk-tools-linux-3859397.zip">http://dl.google.com/android/repository/sdk-tools-linux-3859397.zip</a> -O /tmp/tools.zip &amp;&amp; \<br>    mkdir -p ${ANDROID_HOME} &amp;&amp; \<br>    unzip /tmp/tools.zip -d ${ANDROID_HOME} &amp;&amp; \<br>    rm -v /tmp/tools.zip</pre><pre># Install Android packages &amp; libraries<br>RUN export PATH=$PATH:$ANDROID_HOME/tools/bin &amp;&amp; \<br>    mkdir -p /root/.android/ &amp;&amp; touch /root/.android/repositories.cfg &amp;&amp; \<br>    yes | sdkmanager &quot;--licenses&quot; &amp;&amp; \<br>    sdkmanager --verbose &quot;build-tools;${BUILD_TOOLS}&quot; &quot;platform-tools&quot; &quot;platforms;android-${SDK_TOOLS_API}&quot; \<br>    &amp;&amp; sdkmanager --verbose &quot;extras;android;m2repository&quot; &quot;extras;google;google_play_services&quot; &quot;extras;google;m2repository&quot;</pre><pre># Install pip for grip export README.md to html<br>RUN apk add --no-cache --virtual=.build-dependencies py-pip \<br>    &amp;&amp; pip install --upgrade pip \<br>    &amp;&amp; pip install grip</pre><pre># Install git<br>RUN apk add --no-cache git</pre><pre># Install application dependencies<br><strong>WORKDIR</strong> /workspace<br><strong>COPY</strong> workspace /workspace<br>RUN ./gradlew assembleDebug \<br>    &amp;&amp; ./gradlew testDebugUnitTest \<br>    &amp;&amp; ./gradlew clean</pre><p>In fact, this Dockerfile fixs not only size issue but also duplicate download dependencies and test re-build problems. Let me explain it in detail.<br>First we replace the base image with <strong>openjdk:8-alpine</strong>. And because alpine is different OS, we need use <strong>apk add </strong>instruction to substitute for <strong>apt-get install</strong>. Thanks to <a href="https://www.sandtable.com/reduce-docker-image-sizes-using-alpine/">this blog</a> and <a href="https://github.com/gliderlabs/docker-alpine/blob/master/docs/usage.md">docker-alpine docs</a>, we know how to use apk add and its parameter like <strong>no-cache</strong> and <strong>virtual=.build-dependencies</strong>. We also follow <a href="https://github.com/alvr/alpine-android">this project</a> in GitHub to write the Dockerfile or we would not know the need of Glibc and ca-certificates. And noted to prune the size by removing the downloaded archived files.</p><p>I usually do experiment on local first for easily debugging, and then push to GitLab. Although each RUN instruction will add layer to image and result in more space, it’s helpful to separate different steps into different RUNs. Not only increase readability but especially in develop stage. Only the part we modify in Dockerfile need be re-executed when build image. If we change the instructions in sdkmanager part, it doesn’t download Android SDK tool again, because it’s already saved in previous layer.</p><p>In the beginning, I don’t know Alpine doesn’t show download progress when sdkmanager downloads files. I‘d like to figure out what’s wrong with sdkmanager on Alphine by constantly modifying the Dockerfile, and therefore, benefit from the docker image layers.</p><p>Secondly, to avoid download gradle and other dependencies every time, we create a empty Android application in image builder project, and replace its <strong>2 build.gradle</strong>(project’s and app module’s) and <strong>gradle-wrapper.properties</strong> in gradle/wrapper with application’s. <strong>WORKDIR</strong> is Dockerfile instructions setting the working directory for the following other instructions like RUN, COPY… We use <strong>COPY</strong> instruction to copy the empty application to image and then build, test and clean it to let image contains the required dependencies without dummy build result.</p><p>Finally, we also modify the .yml file of application project that only one stage left now, it executes assembleDebug and testUnitTest sequentially.</p><pre>build:<br>  stage: build_test<br>...</pre><pre>script:<br>    - ./gradlew assembleDebug<br>    - ./gradlew testDebugUnitTest<br>  artifacts:<br>    paths:<br>      - app/build/outputs/<br>      - app/build/reports/tests<br>    expire_in: 2 week</pre><p>That’s it! There’s only one stage, and it still add apk and test result in artifacts. The final result is 9 minutes less than half of original.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B7YMEVzEgoMHXWTKpfhKAA.png" /><figcaption>GitLab pipeline enhanced results</figcaption></figure><p>Hmm… The story is not over. But the blog is almost end.</p><p>There are many parts still can be improved:</p><ol><li>Compared to Jenkins, it takes 9 minutes… still too long</li><li>The docker image size is still too large 1.69GB…(original takes 2.24GB)</li><li>To download dependencies in advance, we need copy application’s build setting to image builder project, and it should be automatically</li></ol><p>I think we will keep this mechanism and maybe in the future find out some methods to improve it or just change to use other CI tools. Anyway, very appreciate my colleagues WC’s and ChengYang’s help about GitLab CI and Docker, and thanks to the knowledge and experience sharing on Web that I didn’t reference them all in the blog. Please feel free to leave your comments and thanks for your reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8739d8a11cee" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>