<?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[Creative Talks - Medium]]></title>
        <description><![CDATA[Sharing learnings on devops, mobile/web dev gathered while creating modern tech companies. - Medium]]></description>
        <link>https://medium.com/creativetalks?source=rss----eb2433510eef---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Creative Talks - Medium</title>
            <link>https://medium.com/creativetalks?source=rss----eb2433510eef---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:20:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/creativetalks" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Distributing npm packages in Gitlab]]></title>
            <link>https://medium.com/creativetalks/distributing-npm-packages-in-gitlab-fd3ebf5bd307?source=rss----eb2433510eef---4</link>
            <guid isPermaLink="false">https://medium.com/p/fd3ebf5bd307</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[yarn]]></category>
            <dc:creator><![CDATA[Honza]]></dc:creator>
            <pubDate>Sat, 23 Apr 2022 20:12:43 GMT</pubDate>
            <atom:updated>2022-04-24T15:38:20.968Z</atom:updated>
            <content:encoded><![CDATA[<h3>Distributing NPM packages in Gitlab</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*TiHKQ5jxdpCG7HA6.png" /></figure><p>Our project has grown into a moment when we needed to extract the React Native UI components from the app repository, so they could be simply reused as a npm dependencies in another apps 🤔.</p><h3>A seek for npm registry.</h3><ol><li>Due to the team size we needed to set some UI maintenance processes, merge requests, code review, code quality checks, you name it…</li><li>We wanted to be able to run unit tests</li><li>We wanted to use <a href="https://storybook.js.org/">Storybook</a>,</li><li>We wanted to keep the costs down.</li></ol><p>Since we host all our repositories on Gitlab, having the npm package registry directly there seemed like a logical thing to do. The registry can be kept as <em>private</em>, so the user has to be authenticated and authorized to access the libraries, or you can share the library as<em> public</em>.</p><blockquote>Note: Gitlab also supports other package registries like Maven, Go, PyPI, Ruby Gems, even Helm! .. and more...</blockquote><h3>Gitlab FTW!</h3><p>Gitlab Package Registry offers two approaches</p><ul><li><strong><em>Project level</em></strong><em> — </em>one Gitlab repository = one npm endpoint</li><li><strong><em>Instance level</em></strong>—whole Gitlab group is one npm endpoint</li></ul><p>The idea is that we’ll have a separate Gitlab group that would have all repositories that we need to ship with npm. So we created a new group called fairo-hq (fairo was already taken 🤭). <strong>Go Instance level Gitlab registry!</strong></p><h3>Publishing the package</h3><p>Firstly, the package needs to be published. To publish the package it’s only necessary to have a repository with package.json and gitlab-ci.yml . It’s simple as that.</p><p>Minimal setup needs at least these to be set:</p><pre><strong>package.json</strong></pre><pre>{<br>  &quot;name&quot;: &quot;@fairo-hq/ui&quot;,<br>  &quot;version&quot;: &quot;0.0.1&quot;<br>}</pre><pre><strong>.gitlab-ci.yml</strong></pre><pre>image: node:16-alpine<br><br>stages:<br>  - publish<br><br>publish:<br>  stage: publish<br>  script:<br>    - echo &quot;@${CI_PROJECT_ROOT_NAMESPACE}:registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/&quot; &gt;&gt; .npmrc<br>    - echo &quot;${CI_API_V4_URL#https?}/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}&quot; &gt;&gt; .npmrc<br>    - npm publish</pre><p>Let’s slow down and see what’s happening here.</p><p>The first command of the .gitlab-ci.yml sets the npm config to point our npm scope to the gitlab endpoint.</p><p>As <a href="https://docs.gitlab.com/ee/user/packages/npm_registry/#package-naming-convention">Gitlab’s documentation mentiones</a>, we cannot freely choose the name of the scope. The scope is determined by the namespace of the Gitlab group, in our case it’s fairo-hq. The npm scope shall be @fairo-hq . The package name (after the slash) is the name of the project, in our case ui. Then, the full name of the package defined in the package.json must be @fairo-hq/ui.</p><p>The second command simply adds an access token to the endpoint, which is then always present in the headers.</p><p>The third command ultimately publishes the package into the registry. This will success only if there’s not the same version already published. Thus it’s good to maybe combine the Gitlab job with only: tags option set, so we can use npm version command to bump the version.</p><p>The good news is that everything we’ve set here is stored in <a href="https://docs.gitlab.com/ee/ci/variables/predefined_variables.html">Gitlab’s predefined variables</a> and there’s no need to set anything. CI_PROJECT_ROOT_NAMESPACE &#39;s value is our namespace fairo-hq, CI_API_V4_URL would probably be https://gitlab.com/api/v4<strong> </strong>(or self-hosted alternative), CI_PROJECT_ID would be your project id and CI_JOB_TOKEN token has all the permissions needed to write to the package registry. Sweet!</p><p>Did I not mention yarn? You can use it to install dependencies, build your library, tests, etc., but the configuration and publish must be done using npm. Using yarn config or .yarnrc, I’ve always received various 404 or 401 errors, even though yarn seemed properly configured. Same goes for the library installation, as long as you store your configuration to .npmrc, the yarn install command works as expected.</p><p>If the pipeline succeeds, you should see your first package in the registry ❤️.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*PgdcBolmsv3Xn52-nSzc8A.png" /></figure><h3>Installing the package</h3><p>This can be set many ways, depending on the project security requirements, but essentially every developer needs to have these few lines in their .npmrc . Same as before, the first line to add an endpoint to our @fairo-hq scope, the rest to assign an access token to it.</p><p>Any Gitlab token that can access the group with read_registry scope will do just fine.</p><pre><strong>.npmrc</strong></pre><pre>&quot;@fairo-hq:registry&quot;=&quot;https://gitlab.com/api/v4/packages/npm/&quot;<br><br>&quot;//gitlab.com/api/v4/packages/npm/:_authToken&quot;=&quot;&lt;&lt;AUTH_TOKEN&gt;&gt;&quot;<br>&quot;//gitlab.com/api/v4/projects/:_authToken&quot;=&quot;&lt;&lt;AUTH_TOKEN&gt;&gt;&quot;</pre><h3>The Catch</h3><p>In order for npm registry to work for instance level, it’s necessary to include both settings for project and instance level, despite otherwise great Gitlab documentation. It simply doesn’t work without it 😏 (again, all sorts of 400/401 errors).</p><p>It’s also worth to mention that project level settings officially require to specify a Project Id, which is not ideal if we want to have instance level npm registry with multiple packages.</p><p>The solution is simple (don’t ask me how we figured this out, it was just pure despair and luck 🥹 ).</p><pre># per Gitlab&#39;s <a href="https://docs.gitlab.com/ee/user/packages/npm_registry/#project-level-npm-endpoint-1">documentation</a>, requires the project id 🤷‍♂️<br>//gitlab.example.com/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}</pre><pre># h̶a̶c̶k̶y̶ Nifty solution<br>//gitlab.example.com/api/v4/projects/:_authToken=${CI_JOB_TOKEN}</pre><p>With this utterly random undocumented solution you should be able to install the package using your favorite package manager.</p><h3>Stay in touch</h3><p>And that’s it. There are many more topics about npm registry auth, bundling the libraries etc, that’s for another time 😊.</p><p>In case the article was helpful we will be grateful if you will follow us here and support us with some claps 👏. In return we will share even more cool tech articles.</p><p>Feel free to comment and ask for details, share your pains and learnings.</p><p>This article was written by tech enthusiasts <a href="https://www.linkedin.com/in/honzajerabek/">Honza</a> &amp; <a href="https://bit.ly/3MlOISe">Miro</a> currently working at <a href="http://creativedock.com/">CreativeDock</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd3ebf5bd307" width="1" height="1" alt=""><hr><p><a href="https://medium.com/creativetalks/distributing-npm-packages-in-gitlab-fd3ebf5bd307">Distributing npm packages in Gitlab</a> was originally published in <a href="https://medium.com/creativetalks">Creative Talks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated versioning of React Native apps via GitLab pipeline]]></title>
            <link>https://medium.com/creativetalks/automated-versioning-of-react-native-apps-via-gitlab-pipeline-f724ddab47da?source=rss----eb2433510eef---4</link>
            <guid isPermaLink="false">https://medium.com/p/f724ddab47da</guid>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Andrej Kuročenko]]></dc:creator>
            <pubDate>Fri, 12 Mar 2021 12:34:25 GMT</pubDate>
            <atom:updated>2021-03-12T12:34:25.742Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QHfBtM7a4aed04rZPmPaSw.jpeg" /></figure><p>You are fixing that annoying bug in your fancy mobile application, looking forward to having it released asap (of course). Finally everything seems to work, all tests pass, the app is built and being uploaded … phew … when suddenly, the build is rejected by the store with a message stating that build with the same version/build number already exists. You are like “mmgh, not again 🙄”, or even maybe “@!#$, NOT AGAIN 😤”</p><p>Familiar?</p><p>Although tolerable in small apps, this is a mandatory and repeated step that is very annoying and a great candidate for automation.</p><p>The project that I currently work on is a banking mobile application written in React Native and distributed for iOS and Android. We do several to dozen releases daily to dev and sometimes even several releases a weekly to prod. Managing versioning manually would be a full time job for one person (including coffee breaks, of course), and two if we would count with a bus factor effect .</p><h4>GIT structure and release management</h4><p>Before we get to the versioning itself, I’d like to introduce how the code flows in our project from feature branch to production. This is an important part as versioning fits well to this particular architecture.</p><p>We are utilizing so called <a href="https://trunkbaseddevelopment.com/">trunk based development</a> — we have only feature/fix branches that are merged directly to master (and features hidden behind feature toggles if needed). This forces us to do small commits to master very often.</p><p>On merge to master a new build is automatically triggered, <strong>build number is incremented</strong> <strong>and the app is released to dev </strong>distribution channel</p><p>Once such an app version is tested and announced as stable, we <strong>update the app version and</strong> <strong>release it to production</strong> by triggering the manual stage in our GitLab pipeline from the same commit (merge) as the dev app was built (configuration differs).</p><p>Let’s take a look at our proposed solution.</p><h3>Where to store version and build number</h3><p>For apipeline (or whatever/whoever builds your app) to be able to access previous app version number and build number this information has to be stored somewhere, ideally in GIT itself.</p><p>Of course if we had only iOS or only Android app, it would make sense to store this information in respective project configurations. In React Native, we want to have a version and build number accessible for iOS/Android projects and JavaScript code, ideally from one place during build.</p><h4>Working with app version number</h4><p>For version we are utilizing package.json and its version attribute which holds app version in <a href="https://semver.org/">semver format</a> . Your favorite package manager, for example yarn, is then able to increment the version with yarn version command. For example:</p><pre>yarn version --path<br>yarn version --minor<br>yarn version --major</pre><p>This can be added to package.json scripts and called manually or from CI:</p><pre>&quot;bump-version:minor&quot;: &quot;yarn version --minor --no-git-tag-version&quot;,<br>&quot;bump-version:major&quot;: &quot;yarn version --major --no-git-tag-version&quot;,<br>&quot;bump-version:patch&quot;: &quot;yarn version --patch --no-git-tag-version&quot;,</pre><p>Note the --no-git-tag-version flag. Normally the yarn version command also creates a GIT tag, which we do not want at the moment as we will use GIT tags for different purposes.</p><p>Let’s test it. Say we have version 2.0.1 in our package.json and we want to release a fix version 2.0.2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*ki0y82LsMA6kHrTlXd0Xag.png" /></figure><p>We just run yarn bump-version:patch and the version is changed in package.json file, ready to be committed to GIT</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*xo9q1ciBl8G_PKM7F4fMsA.png" /></figure><h4>Working with a build number</h4><p>We wanted to be able, by single look at GIT history, to understand which commit relates to particular application build. This helps to understand what features are in what app version or what fixes are missing in users installation when solving production incidents.</p><p>Naturally we chose to store build numbers into GIT tags. Each merge to master represents build number increment and thus has its own numeric GIT tag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*_SErbTBaUB9oV4rGNc-xTA.png" /></figure><p>On paper this sounds cool, but making it work in GitLab pipelines is not as straightforward as one would expect. This is a stage in our .gitlab-ci.yml that handles the build number update:</p><pre>bump_build_number:<br>  image: node:latest<br>  stage: bump_build_number<br>  script:<br>    - source ./scripts/gitlab/setup-git-rw.sh<br>    - source ./scripts/gitlab/export-CI_LATEST_BUILD_NUMBER.sh<br><br>    <em># bump build number<br>    </em>- export CI_LATEST_BUILD_NUMBER=$(($CI_LATEST_BUILD_NUMBER+1))<br><br>    <em># push updated tag into git repo<br>    </em>- git tag $CI_LATEST_BUILD_NUMBER<br>    - git push origin $CI_LATEST_BUILD_NUMBER<br>  only:<br>    - master</pre><p>This stage is executed before the release stage is started as that one already uses the newly created GIT tag when baking the app version into the code.</p><p>Let’s examine step by step what is happening here:</p><ol><li>We change GIT repository from read only to read/write</li><li>We get last build version from GIT tags</li><li>We increment it and store as a new tag and push the changes</li></ol><p><strong>Making repository read/write</strong> — when GitLab runs pipeline, it checkouts the repository in read-only mode which is sufficient for most cases but we want to be able to increment GIT tag. And this operation already requires write access to the repository so we want to tweak the setup a bit by running the source ./scripts/gitlab/setup-git-rw.sh script.</p><blockquote>be aware — in pipeline config this script is called with source prefix command. This will run the content of the script in same bash instance as GitLab runner is using, otherwise the changes or ENV variables might not be visible/available to the runner context</blockquote><p>Honestly, following bash scripts is not something I would hang on a wall in our office, but it does the job. Content of ./scripts/gitlab/setup-git-rw.sh:</p><pre><strong>#!/bin/bash<br></strong>#<br># Expected to run in GitLab job<br>#<br># Configures job environment so it is possible to write into git repo.<br># Variables are passed from GitLab config or job `script`/`variables`<br>#<br><br># setup ssh for pushing into git repo<br>mkdir -p ~/.ssh &amp;&amp; chmod 700 ~/.ssh<br>ssh-keyscan gitlab.com &gt;&gt; ~/.ssh/known_hosts &amp;&amp; chmod 644 ~/.ssh/known_hosts<br>eval $(ssh-agent -s)<br>ssh-add &lt;(echo &quot;$SSH_PRIVATE_KEY&quot;)<br><br># prepare git config for pushing remote repo<br># replace http to ssh git url to use ssh key auth<br>GIT_REPOSITORY_URL=$(echo $CI_REPOSITORY_URL | sed -e &#39;s/.*\@/git\@/&#39; -e &#39;s/\//:/&#39;)<br>git remote set-url --push origin $GIT_REPOSITORY_URL<br><br># refresh git tags (gitlab uses fetch instead of clone which does not refresh deleted tags)<br>git tag -l | xargs git tag -d<br>git fetch --tags</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*rqXf3Bply4FHuXpu.jpg" /></figure><blockquote>Note: for a premium or self-managed version of GitLab it should be enough to use <a href="https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html">Gitlab project access tokens</a> to replicate this DIY script.</blockquote><p>Before running the script we had to also add a private SSH key into GitLab CI variables. Using this key the GitLab job is authenticating to the GIT repository with write access. Simply generate new SSH key by running ssh-keygen (do not add any password to protect the key) and copy the key into CI variables in GitLab (Project &gt; Settings &gt; CI/CD &gt; Variables):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*U75JZntTQVDpb7upl7hteg.png" /></figure><p>Also here is a script for <strong>getting the latest build number from GIT tags </strong>which is also used in pipeline setup. Content of ./scripts/gitlab/export-CI_LATEST_BUILD_NUMBER.sh:</p><pre><strong>#!/bin/bash<br></strong>#<br># Exports latest build number from the git tag into a variable later used in pipeline job<br>#<br># refresh all tags from remote <br>git fetch --tags &gt;/dev/null<br><br># get latest tag - we search for numeric tags only sorted by creation date<br>LATEST_TAG=$(git for-each-ref --sort=authordate --format &#39;%(refname:short)&#39; &#39;refs\/tags\/[0-9][0-9]*&#39; | tail -1)<br># if tag not found, the default build number will be 1<br>CI_LATEST_BUILD_NUMBER=${LATEST_TAG:-1}<br><br>echo &quot;Got version number ${CI_LATEST_BUILD_NUMBER}&quot;<br># export for use in CI stage <br>export CI_LATEST_BUILD_NUMBER</pre><p>The rest is being solved in the aforementioned GitLab stage configuration. Now each time this stage is being executed it creates a new GIT tag 🥳 (do not forget to run git fetch --tags on local machine to see changes).</p><p>So, we have the app version and the build number updated, but how to use it in React Native app? 🤔</p><h3>Using version and build number in React Native app</h3><p>Let’s take a look on how to propagate app version and build number into an app. In our stack we are using Fastlane tool to orchestrate builds and releases.</p><p>React Native app consists of three parts that need access to the app version and build number. Those are:</p><ol><li>JavaScript code — in case you want to show this information in your application</li><li>iOS project configuration — for AppStore to understand and use this information during release management</li><li>Android project configuration — for Play Store to understand and use this information during release management</li></ol><p>Fastlane works well with .env files, which is perfect as React Native can work with ENV variables via react-native-config library. Our .env file has following variables defined with default values that are overridden during build:</p><pre>// .env<br>VERSION=1.0.0<br>BUILD_NUMBER=1</pre><p>To update these values we use a custom script that reads the app version from package.json and build number from GIT tag and replaces them in the .env file. Let’s say this script is called setAppVersionInDotEnvFile.sh 🤓</p><pre><strong>#!/bin/bash<br></strong>#<br># Exports latest semantic version from package.json and  <br># latest build number from git tag and replaces in .env<br># for later build process<br>#<br><br>ENV_FILE=${1:-&quot;.env&quot;}<br><br>export VERSION=$(yarn run -s package-version)<br><br>git fetch --tags &gt;/dev/null<br>LATEST_TAG=$(git for-each-ref --sort=authordate --format &#39;%(refname:short)&#39; &#39;refs\/tags\/[0-9][0-9]*&#39; | tail -1)<br>export BUILD_NUMBER=${LATEST_TAG:-1}<br><br># sed works a bit differently on mac than on linux<br>if [ &quot;$(uname)&quot; == &quot;Darwin&quot; ]; then<br>  sed -i &#39;&#39; &quot;s/VERSION=.*/VERSION=$VERSION/g&quot; $ENV_FILE<br>  sed -i &#39;&#39; &quot;s/BUILD_NUMBER=.*/BUILD_NUMBER=$BUILD_NUMBER/g&quot; $ENV_FILE<br>else<br>  sed -i &quot;s/VERSION=.*/VERSION=$VERSION/g&quot; $ENV_FILE<br>  sed -i &quot;s/BUILD_NUMBER=.*/BUILD_NUMBER=$BUILD_NUMBER/g&quot; $ENV_FILE<br>fi</pre><h4>Accessing ENV variables in ReactNative JavaScript</h4><p>To access ENV variables from JavaScript code use <a href="https://github.com/luggit/react-native-config">React Native Config</a> library. In our case:</p><pre>import <strong><em>env </em></strong>from &#39;react-native-config&#39;;</pre><pre>const <strong><em>config </em></strong>= {<br>  version: <strong><em>env</em></strong>.VERSION,<br>  buildNumber: <strong><em>env</em></strong>.BUILD_NUMBER,<br>}</pre><h4>Updating version and build number for iOS</h4><p>Now we can use it in Fasltane Fastfile to set version and build number in xcode project:</p><pre>desc &quot;Set version and build number&quot;<br>lane :sync_version do<br>  sh(&quot;setAppVersionInDotEnvFile.sh .env&quot;)<br><br>  version = get_properties_value(key: &quot;VERSION&quot;, path: ENV[&#39;ENVFILE&#39;])<br>  buildNumber = get_properties_value(key: &quot;BUILD_NUMBER&quot;, path: ENV[&#39;ENVFILE&#39;])<br><br>  increment_build_number(<br>    xcodeproj: &#39;./ios/myproject.xcodeproj&#39;,<br>    build_number: buildNumber<br>  )<br>  increment_version_number(<br>    xcodeproj: &#39;./ios/myproject.xcodeproj&#39;,<br>    version_number: version<br>  )<br>end</pre><h4>Updating version and build number for Android</h4><p>For android config we have to change just few lines:</p><pre>desc &quot;Set version and build number&quot;<br>lane :sync_version do<br>  sh(&quot;setAppVersionInDotEnvFile.sh .env&quot;)<br><br>  version = get_properties_value(key: &quot;VERSION&quot;, path: ENV[&#39;ENVFILE&#39;])<br>  buildNumber = get_properties_value(key: &quot;BUILD_NUMBER&quot;, path: ENV[&#39;ENVFILE&#39;])<br><br>  increment_version_code(<br>    gradle_file_path: &quot;./android/app/build.gradle&quot;,<br>    version_code: Integer(buildNumber)<br>  )<br><br>  increment_version_name(<br>    gradle_file_path: &quot;./android/app/build.gradle&quot;,<br>    version_name: version<br>  )<br>end</pre><p>The sh script and both Fastlane lanes (for iOS and Android) will change files in the project so it would make sense to clean the GIT repo after each such build.</p><p>After this you are ready to run the build and release your app. If you are interested in how to do so using Fastlane and make the process from git push till having released an app in AppStore or PlayStore fully automated, follow us and read the followup articles on Fastlane setup with GitLab pipelines.</p><h3>Stay in touch</h3><p>In case the article was helpful we will be grateful if you will follow us here and support us with some claps 👏. In return we will share even more cool tech articles.</p><p>Feel free to comment and ask for details, share your pains and learnings.</p><p>This article was written by tech enthusiasts <a href="https://taplink.cc/andrejkurocenko">Andrej</a> &amp; <a href="https://www.linkedin.com/in/honzajerabek/">Honza</a> currently working at <a href="http://creativedock.com/">CreativeDock</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f724ddab47da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/creativetalks/automated-versioning-of-react-native-apps-via-gitlab-pipeline-f724ddab47da">Automated versioning of React Native apps via GitLab pipeline</a> was originally published in <a href="https://medium.com/creativetalks">Creative Talks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up GitLab runner on AWS Mac EC2 for React Native iOS builds]]></title>
            <link>https://medium.com/creativetalks/setting-up-gitlab-runner-on-aws-mac-ec2-for-react-native-ios-builds-17ae2e711de8?source=rss----eb2433510eef---4</link>
            <guid isPermaLink="false">https://medium.com/p/17ae2e711de8</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Andrej Kuročenko]]></dc:creator>
            <pubDate>Thu, 04 Mar 2021 13:40:01 GMT</pubDate>
            <atom:updated>2021-03-04T13:40:01.664Z</atom:updated>
            <content:encoded><![CDATA[<p>While building and provisioning <a href="https://www.fairo.com.ua/">Fairo banking app</a> we have spent quite some time on setting up the CI/CD processes in GitLab for our mobile application that is written in React Native. In this article we will present step by step guide on how to create AWS EC2 Mac instances and how to set up necessary tooling for automated builds of iOS React Native apps using GitLab and its runners.</p><p>Namely we will focus on this steps:</p><ul><li>Creating Mac powered EC2 instance</li><li>Setting up the tooling for iOS builds on remote EC2 Mac instance</li><li>Registering, running and verifying GitLab runner on remote Mac instance</li></ul><h3>Motivation</h3><p>Having dozens of merges into master branch daily we needed to automate our delivery pipeline in order to provide latest builds to our testers and promote stable builds to beta/production.</p><p>For iOS we have started out by having old MacBook Pro (2015 series) lying on the table in the office with GitLab runner installed connected to the internet via local WiFi. So all the steps can be reproduced for local machines also👌.</p><p>Switching to AWS EC2 Mac instance was an attempt to improve performance of build machine but also security, stability and scalability.</p><h3>Topics to consider before choosing Mac powered EC2 instance</h3><p><strong>Setup — </strong>Amazon EC2 Mac instances are built on Apple Mac mini computers, featuring 8th Generation 3.2GHz (4.6GHz turbo) Intel Core i7 processors with 6 physical/12 logical cores, and 32GiB of Memory.</p><p>The OS currently supported are macOS 10.14 (Mojave) 10.15 (Catalina) and macOS 11 (Big Sur).</p><p><strong>Availability — </strong>The Mac instances are currently available in regions: US East (N. Virginia), US East (Ohio), US West (Oregon), Europe (Ireland), Asia Pacific (Singapore) and more.</p><p><strong>Pricing — </strong>When it comes to costs, running an EC2 Mac instance can be pretty pricy. Mac instances are available only as bare metal instances on Dedicated Hosts with a minimum allocation period of 24 hours. Simply said, <strong>spinning up the instance will cost you just under $26 a day</strong> ($1.083 per hour).</p><p><strong>Scaling — </strong>Dedicated hosts cannot be attached to Auto Scaling Group.</p><p>If these potential problems did not scare you, let’s continue!</p><h3>Creating the EC2 build machine</h3><p>In the first step you have to allocate the dedicated host. This can be done via AWS Console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*gGdA3ENPuVpgXXmQtGgREQ.png" /></figure><p>or just simply running the following <strong>command</strong>:</p><pre>aws ec2 allocate-hosts --region us-east-1 --availability-zone us-east-1b --quantity 1 --instance-type mac1.metal --tag-specifications &#39;ResourceType=dedicated-host,Tags=[{Key=Name,Value=mac-1}]&#39;</pre><p>In the console, you should see a newly created dedicated host<strong><em>.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_QX95AF4WqaD-1dB80M6Cg.png" /></figure><p>To launch the instance from console, go to EC2 instances and choose one of macOS presented. The instance type should be <strong>mac1.metal</strong>. Make sure you choose the dedicated instance you just allocated as a host. The instance should be launched in a <strong>public</strong> subnet so it gets a public ip associated.</p><p>AWS Mac instances come with 60 GB disk size out of the box. To be able to fit Xcode, do frequent builds and download all JavaScript, Java and Cocoapods dependencies we need to allocate larger storage volume.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RwThduSYCnLq5PpXi2LHKg.png" /></figure><p>The important step is to configure security group to allow ssh access from your IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DKX-UoIphuR0IX3eLFzaKA.png" /></figure><p>Click <strong>Review and Launch</strong></p><p>You will be prompted with an option to create a <strong>new</strong> <strong>key pair</strong> or use existing one. Create a new one a download it.</p><p><strong>Important</strong>: Save your keys securely. Once loosing it, you will not be able to access the instance. The key pairs can be rotated, but you have to follow a complicated “instance recovery” procedure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*Ih3AK3ex3TkHEwXx8S6J9Q.png" /></figure><p>Click <strong>Launch instances</strong>.</p><p>In a couple of moments, you should see a new running instance with public ip associated. 🍻</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IUJZcI2KbaMUA0uLK3t3_w.png" /></figure><h3>Connecting to the remote Mac via terminal</h3><p>Once the instance passes status checks, you can connect to it using user user-ec2 and public ip address of started instance. After connecting you can add other users too</p><pre>ssh -i mac-1.pem ec2-user@xxx.xxx.xxx.xxx</pre><p>you can save this command as an alias into your ~/.bashrc or ~/.zshrc depending on which shell you are using. For example add this into your rc file (do not forget to reload terminal afterwards):</p><pre>alias =&#39;ssh -i ~/.ssh/mac-1.pem ec2-user@xxx.xxx.xxx.xxx&#39;</pre><p>Now if you type  into terminal, you will get connected to the remote machine.</p><blockquote>NOTE: In case you are facing timeouts when connecting to the machine, be sure to check the inbound rules of security group associated with EC2 instance. You should allow the access only from trusted IP addresses.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oIVZ0RUXbiIEPMLPvvxBNA.png" /></figure><h4>Installing oh my zsh (optional, but recommended)</h4><p>This step is optional, but highly recommended. <a href="https://ohmyz.sh/">Oh My Zsh</a> is cool and colourful shell that makes the work in terminal fun. You can also replace the PS1 environment variable in your ~/.zshrc to make prompt look awesome (and different from your local machine):</p><pre>export PS1=&#39;🍏☁️  %(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)&#39;</pre><p>Paste the code above into your shell config (e.g. ~/.zshrc ) and then reload config in current terminal window by running . ~/.zshrc or open new terminal window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*tT13Ur40mbu_djc2er7nUA.png" /></figure><h3>(Optional) Attaching bigger disk</h3><p>In case you will run out of space on your MacOS instance, there is a possibility to attach another volume.</p><p>To attach the volume follow the instructions in the AWS documentation <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-mac-instances.html#mac-instance-increase-volume">Increase the size of an EBS volume on your Mac instance</a>. Here are the commands copied from the documentation that you need to run in order to attach the volume:</p><p><strong>To make increased disk space available for use</strong></p><p>Copy and paste the following commands from remote Mac instance. When prompted, enter a ‘y’.</p><pre>PDISK=$(diskutil list physical external | head -n1 | cut -d&quot; &quot; -f1)</pre><pre>APFSCONT=$(diskutil list physical external | grep &quot;Apple_APFS&quot; | tr -s &quot; &quot; | cut -d&quot; &quot; -f8)</pre><pre>sudo diskutil repairDisk $PDISK</pre><p>Copy and paste the following command.</p><pre>sudo diskutil apfs resizeContainer $APFSCONT 0</pre><p>If successful, you should see have more space on disk:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qAjH2MHWI9iftRUuwL_GXQ.png" /></figure><h3>Installing necessary tooling for iOS builds</h3><p>To be able to run iOS builds on mac machine we need Xcode, node, yarn and ruby bundler that is used to install and run Fastlane.</p><h4>Cloning repo with React Native app to remote machine</h4><p>It helped a lot to clone app repository on remote Mac machine and at first run manually all the steps that will eventually run in the GitLab runner to check that all works as expected. To do so we needed to create new SSH key (without passphrase) on remote Mac machine. Run following command:</p><pre>ssh-keygen</pre><p>Confirm all the options without inputing any passwords and once done copy the content of ~/.ssh/id_rsa.pub and paste it to the SSH keys in the GitLab user settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G8YJgFurQT6e82Miriy5qw.png" /></figure><p>Then clone the repository onto the remote Mac machine.</p><h4>Installing Xcode</h4><p>This is the only step that cannot be automated or done via CLI (or at least we didn’t find a way how to do it). In order to install Xcode you will have to connect remotely to the machine via GUI and install the Xcode via AppStore.</p><p><strong>Important: </strong>To be able to log into an instance with VNC, you need to reset the password of ec2-user.</p><pre>sudo /usr/bin/dscl . -passwd /Users/ec2-user &lt;your password&gt;</pre><blockquote>If asked for <em>sudo</em> password, just hit <em>Enter</em></blockquote><p>To connect remotely with GUI from Mac OS open terminal and connect to remote Mac machine via SSH with port tunnelling option:</p><pre>ssh -L 5900:localhost:5900 -i mac-1.pem ec2-user@xxx.xxx.xxx.xxx</pre><p>Then open finder and press Cmd+K and input the vnc://localhost:5900 into the pop up window, confirm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YRCXnEGAdK7TSORvSlGwDA.png" /></figure><p>This will connect you to the remote Mac with GUI. You will have to login as ec2-user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*l29yaZVHuwQI8wHAAC9zKw.png" /></figure><p>Open the AppStore, login to your Apple ID and install the latest version of the Xcode.</p><p>After Xcode is installed, try to run it and accept all the licenses. You can do this also from terminal by running the following command (this is required only once):</p><pre>sudo xcodebuild -license accept</pre><blockquote>If asked for <em>sudo</em> password, just hit <em>Enter</em></blockquote><h4>Installing node</h4><p>To be able to compile JavaScript we need node v &gt;= 12 and yarn packager. We can install node from brew, which will install latest node version:</p><pre>brew install node</pre><p>and then install yarn instead of npm</p><pre>npm install --global yarn</pre><p>Try to verify the installation by installing project JS dependencies via yarn.</p><pre>cd [project_folder] &amp;&amp; yarn</pre><h4>Installing ruby bundler</h4><p>For orchestration of the build process we use Fastlane tool which is based on Ruby and we need Ruby bundler to run it. To install just run</p><pre>sudo gem install bundler</pre><p>Bundler version should match the version in Gemfile.lock in the project folder (if you have any). To install a matching version you can run the following command from the project folder. This command will read version from Gemfile.lock and use it for bundler installation:</p><pre>sudo gem install bundler -v &quot;$(grep -A 1 &quot;BUNDLED WITH&quot; Gemfile.lock | tail -n 1)&quot;</pre><p>It is important to have only one version of ruby installed on remote Mac machine — the system one. We have also tried to install bundler via rvm but later we have experienced that GitLab runner was returning “<strong>ERROR: Build failed with: exit status 1</strong>” immediately after start and it was due to present rvm folders.</p><blockquote>In case you need to uninstall <em>rvm</em>, follow this <a href="https://stackoverflow.com/a/4747195/816456">StackOverflow response</a>.</blockquote><p><strong>Solving the ruby/config.h’ file not found error</strong></p><p>When installing the bundler you might experience an error that states that “<strong>‘ruby/config.h’ file not found</strong>’. We didn’t find a better solution on the internet other than creating a symlink to the ruby version brought by Xcode. The path below might differ a bit on different machines, but with little effort it’s possible to find the location of ruby in Xcode folder structure. For us the path was following:</p><pre>cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0</pre><p>And the symlinks that needs to be done (from the folder above) is:</p><pre>sudo ln -s universal-darwin20 universal-darwin19</pre><p>By this we should have all the necessary tooling installed.</p><h3>Installing, registering and running the runner</h3><p>To install runner on mac we have used the <a href="https://docs.gitlab.com/runner/install/osx.html">official documentation</a> (the manual installation). Just run:</p><pre>sudo curl --output /usr/local/bin/gitlab-runner &quot;https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64&quot;</pre><p>This will install runner onto the system. Don’t forget to make the binaryexecutable:</p><pre>sudo chmod +x /usr/local/bin/gitlab-runner</pre><h4>Registering the runner.</h4><p>Before runner will accept any Jobs from GitLab Pipeline it has to be 1) registered, 2) started, 3) run 🥺</p><p>To register the runner we will need the token from GitLab (can be found in GitLab project &gt; Settings &gt; CI/CD &gt; Runners (expand)). To register runner, run on remote Mac:</p><pre>gitlab-runner register</pre><p>And input following attributes when asked:</p><ul><li><strong>GitLab URL</strong>: <a href="https://gitlab.com/">https://gitlab.com/</a></li><li><strong>Token</strong> [the one copied from GitLab]</li><li><strong>Tag</strong>: you can chose to tag the runner, then it will be building only tagged stages in gitlab-ci.yml. We chose to tag our runner so that this runner accepts only iOS build Jobs. We have created a tag mac-in-cloud</li></ul><h4>Running the runner</h4><p>First we have to start the runner</p><pre>gitlab-runner start</pre><p>and verify that it has connected to the GitLab (go to same location as where the token was generated in GitLab settings):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dk9NLji6s2Fh-IrqfwEgNg.png" /></figure><p>Such runner will still not be taking any jobs from the pipeline and the jobs will be in pending status. For runner to be able to take jobs from pipeline we also have to run the runner:</p><pre>gitlab-runner run</pre><p>or use the following version of the command to start it in the background</p><pre>gitlab-runner run &amp;</pre><p>Check the status of the runner.</p><h3>Conclusions</h3><p>At this point all the tooling should be installed and runner up and ready to accept new jobs. If you have .gitlab-ci.yml configured with Fastlane already you can try to build your app on a remote Mac machine. If not, read further.</p><p>In next article we will configure GitLab pipeline and Fastlane tool to build and securely sign an application on remote Mac machine and distribute it to Firebase, Play Store or AppStore.</p><h3>Stay in touch</h3><p>In case the article was helpful we will be grateful if you will follow us here and support us with some claps 👏. In return we will share even more cool tech articles.</p><p>Feel free to comment and ask for details, share your pains and learnings.</p><p>This article was written by tech enthusiasts <a href="https://taplink.cc/andrejkurocenko">Andrej</a> &amp; <a href="https://www.instagram.com/novotnymira/">Miro</a> currently working at <a href="http://creativedock.com/">CreativeDock</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17ae2e711de8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/creativetalks/setting-up-gitlab-runner-on-aws-mac-ec2-for-react-native-ios-builds-17ae2e711de8">Setting up GitLab runner on AWS Mac EC2 for React Native iOS builds</a> was originally published in <a href="https://medium.com/creativetalks">Creative Talks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>