<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Geoff B.</title>
    <description>The latest articles on DEV Community by Geoff B. (@__geoff___).</description>
    <link>https://dev.to/__geoff___</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F7212%2F05lGa-_M.jpg</url>
      <title>DEV Community: Geoff B.</title>
      <link>https://dev.to/__geoff___</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/__geoff___"/>
    <language>en</language>
    <item>
      <title>How to deploy a Next.js application to GitLab Page</title>
      <dc:creator>Geoff B.</dc:creator>
      <pubDate>Fri, 19 Apr 2024 10:05:04 +0000</pubDate>
      <link>https://dev.to/__geoff___/how-to-deploy-a-nextjs-application-to-gitlab-page-5eic</link>
      <guid>https://dev.to/__geoff___/how-to-deploy-a-nextjs-application-to-gitlab-page-5eic</guid>
      <description>&lt;p&gt;Next.js has become a standard choice for developing React applications, offering various deployment options across different platforms. While &lt;a href="https://vercel.com/"&gt;Vercel&lt;/a&gt; is a popular choice for building and deployment, specific project requirements may require deployment to GitLab. In this guide, I'll illustrate the process of deploying a Next.js application to GitLab Pages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.gitlab.com/ee/user/project/pages/"&gt;GitLab Pages&lt;/a&gt; allows you to publish a static website directly from a repository. In this tutorial, we'll create a pipeline that generates a static export of a Next.js application and publishes it automatically after each commit. Let's start by creating a simple Next.js application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a Next.js application
&lt;/h2&gt;

&lt;p&gt;For this project I will be using the current LTS version of Node.js (v20.12.2), both locally and in the pipeline. It is important to keep this version consistent throughout the whole process to ensure that the features used locally will also work in the pipeline.&lt;/p&gt;

&lt;p&gt;To create a new Next.js application, we need to run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-next-app@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will be prompted to answer a few questions to select the configuration that suits you best. Personally, I opted for TypeScript, ESLint, Tailwind CSS and the App Router. Additionally I installed &lt;a href="https://ui.shadcn.com/docs/installation/next"&gt;shadcn/ui&lt;/a&gt; for the button component and Prettier for a consistent code formatting. While the application itself isn't the primary focus, I created two pages to showcase routing and included an image for asset management. &lt;/p&gt;

&lt;p&gt;Now, it is essential to create a new GitLab repository to store our newly created application before jumping into the export and deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup a new gitlab repo
&lt;/h2&gt;

&lt;p&gt;For this project, I will be creating a&amp;nbsp;public repository where my Next.js application will be versioned. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O_vHfrdP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1713519690338/d9b84003-809c-4b5e-9938-bfeec7c36296.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O_vHfrdP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1713519690338/d9b84003-809c-4b5e-9938-bfeec7c36296.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="setup gitlab repo" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once completed, we can proceed to link our Next.js application with the new repository. To achieve this, navigate to the directory of the application and initialize Git.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init &lt;span class="nt"&gt;--initial-branch&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;main

git remote add origin git@gitlab.com:geoffb/deploy-nextjs-app-with-gitlab.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this setup is done, we can make our initial commit to push the entire application to the repository. You can access the application here: &lt;a href="https://gitlab.com/geoffb/deploy-nextjs-app-with-gitlab"&gt;https://gitlab.com/geoffb/deploy-nextjs-app-with-gitlab&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The only remaining task is to adjust the configuration of the Next.js application for static export and create a pipeline file to publish the website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a static export and publish it!
&lt;/h2&gt;

&lt;p&gt;In the Next.js documentation &lt;a href="https://nextjs.org/docs/app/building-your-application/deploying/static-exports"&gt;it states&lt;/a&gt; that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Next.js enables starting as a static site or Single-Page Application (SPA), then later optionally upgrading to use features that require a server.&lt;br&gt;&lt;br&gt;
When running&amp;nbsp;&lt;code&gt;next build&lt;/code&gt;, Next.js generates an HTML file per route. By breaking a strict SPA into individual HTML files, Next.js can avoid loading unnecessary JavaScript code on the client-side, reducing the bundle size and enabling faster page loads.&lt;br&gt;&lt;br&gt;
Since Next.js supports this static export, it can be deployed and hosted on any web server that can serve HTML/CSS/JS static assets.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To build a static export you will need to edit the &lt;code&gt;next.config.mjs&lt;/code&gt; and add this few lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="cm"&gt;/** @type {import('next').NextConfig} */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nextConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;images&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;unoptimized&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;export&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;nextConfig&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;output&lt;/strong&gt;: specify that we will do a static export&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;images/unoptimized&lt;/strong&gt;: will serve the images as they are instead of being optimized by the &lt;code&gt;next/image&lt;/code&gt; component. &lt;a href="https://nextjs.org/docs/app/api-reference/components/image#unoptimized"&gt;https://nextjs.org/docs/app/api-reference/components/image#unoptimized&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that our application is ready to be built as a static site, we need to tell GitLab what to publish. To accomplish this, let's create a new file named &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; at the root of our repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node:20.12.2-alpine3.19&lt;/span&gt;

&lt;span class="na"&gt;stages&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;build&lt;/span&gt;

&lt;span class="na"&gt;pages&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;stage&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;build&lt;/span&gt;
  &lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;npm install&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;npm run build&lt;/span&gt;
  &lt;span class="na"&gt;artifacts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;out&lt;/span&gt;
  &lt;span class="na"&gt;publish&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;out&lt;/span&gt;
  &lt;span class="na"&gt;only&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line specifies the Docker image to be used for executing the job within the pipeline. It's worth noting that I've opted for the same node version as previously specified, matching my local environment.&lt;/p&gt;

&lt;p&gt;This pipeline currently consists of only one stage, the build stage. You have the flexibility to incorporate additional stages, such as a linting stage, according to your requirements.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;pages&lt;/code&gt; keyword tells the pipeline to upload the result of the job to the GitLab Pages. In this block of code we need to specify a few things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;stage&lt;/strong&gt;: indicating the stage in which the job should run&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;script&lt;/strong&gt;: the different commands to execute. To generate a static export of the Next.js application we only need to install the dependencies and build it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;artifacts&lt;/strong&gt;: correspond to the output of the job, it is a list of files and directories. When exporting a Next.js application, the default output directory is typically named &lt;code&gt;out&lt;/code&gt; (this can be configured in the &lt;code&gt;next.config.mjs&lt;/code&gt; file).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;publish&lt;/strong&gt;: to use a different content directory other than the default &lt;code&gt;public&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;only&lt;/strong&gt;: specifying to execute the pipeline on our current branch &lt;code&gt;main&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After committing the changes to both the &lt;code&gt;next.config.mjs&lt;/code&gt; and the new &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; file, a pipeline will be automatically executed as you can see below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fdMpL2sQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1713519602499/4db91f87-a0ab-4b30-8f1f-472a2f4b6048.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fdMpL2sQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1713519602499/4db91f87-a0ab-4b30-8f1f-472a2f4b6048.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="running pipeline" width="800" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The pipeline will execute the jobs within the stages. In this scenario, we have a straightforward pipeline with one job in one stage. This job will generate a static export of the Next.js application, which will then be automatically published to GitLab Pages. Once everything is done we can see that then pipeline succeeded:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4AELMLJ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1713519620856/e0d8bea4-36bf-4ea4-88e4-6d0c1e4a87b5.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4AELMLJ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1713519620856/e0d8bea4-36bf-4ea4-88e4-6d0c1e4a87b5.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="pipeline successful" width="800" height="221"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to access the static website and explore its functionality by following this link. You can test navigation between the two pages and view the image asset. &lt;a href="https://deploy-nextjs-app-with-gitlab-geoffb-985ba1d87bd969f03ee8f4e83b.gitlab.io/"&gt;https://deploy-nextjs-app-with-gitlab-geoffb-985ba1d87bd969f03ee8f4e83b.gitlab.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s0jEXIhG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1713519665681/5b797fe1-0878-4a88-bfa1-0d861ade245c.gif%3Fauto%3Dformat%2Ccompress%26gif-q%3D60%26format%3Dwebm" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s0jEXIhG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1713519665681/5b797fe1-0878-4a88-bfa1-0d861ade245c.gif%3Fauto%3Dformat%2Ccompress%26gif-q%3D60%26format%3Dwebm" alt="application demo" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In conclusion, we can say that Next.js provides a range of deployment solutions across diverse platforms. Throughout this guide, we've explored the steps involved in deploying a Next.js application to GitLab Pages, which includes many interesting topics that can be explored and expended.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>gitlab</category>
      <category>gitlabpages</category>
      <category>deployment</category>
    </item>
    <item>
      <title>Managing local resources with Tilt or how do I setup my local dev environment</title>
      <dc:creator>Geoff B.</dc:creator>
      <pubDate>Wed, 27 Jan 2021 19:58:27 +0000</pubDate>
      <link>https://dev.to/__geoff___/managing-local-resources-with-tilt-or-how-do-i-setup-my-local-dev-environment-2hd4</link>
      <guid>https://dev.to/__geoff___/managing-local-resources-with-tilt-or-how-do-i-setup-my-local-dev-environment-2hd4</guid>
      <description>&lt;p&gt;I have been working with Tilt for almost a year now and I find it very useful to manage local resources and applications. I'm currently working on a side project called flashcards and I have done the setup of my local environment with Tilt.&lt;/p&gt;

&lt;p&gt;What we want to achieve here is to setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A local database running in a container&lt;/li&gt;
&lt;li&gt;A bare Phoenix project (API)&lt;/li&gt;
&lt;li&gt;A bare React project&lt;/li&gt;
&lt;li&gt;A Tiltfile to rule them all&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the tree of my directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── backend
├── docker
│   └── docker-compose.yml
├── env
│   └── postgres.env
├── frontend
└── Tiltfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setup the database
&lt;/h2&gt;

&lt;p&gt;Prerequisite:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have Docker installed and running&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First let's setup the docker-compose.yml file. I want to have a simple postgres database running in a docker container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.8'
services:
  postgres:
    image: postgres:13
    container_name: flashcards_database
    volumes:
      - postgres-data:/var/lib/postgresql/data/
    env_file:
      - ../env/postgres.env
    ports:
      - 5432:5432

volumes:
  postgres-data:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing out of the ordinary here, the only thing I like to do is having the environment variables in an external file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POSTGRES_USER=geoffroy_baumier
POSTGRES_PASSWORD=password
POSTGRES_DB=flashcards_dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfect, now that this is done I can spin it up in order to setup my Phoenix project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker-compose -f docker/docker-compose.yml up
[...]
Creating fashcards_database ... done
Attaching to fashcards_database
[...]
fashcards_database | 2021-01-27 18:18:23.825 UTC [1] LOG:  database system is ready to accept connections
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database is now listening on the port default postgres port 5432.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup the API
&lt;/h2&gt;

&lt;p&gt;Prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have erlang installed&lt;/li&gt;
&lt;li&gt;Have elixir installed&lt;/li&gt;
&lt;li&gt;And have the database running&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;"If we have just installed Elixir for the first time, we will need to install the Hex package manager as well. Hex is necessary to get a Phoenix app running (by installing dependencies) and to install any extra."&lt;/em&gt;&lt;br&gt;
&lt;a href="https://hexdocs.pm/phoenix/installation.html"&gt;Source: hexdocs.pm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's install the hex package manager:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mix local.hex
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's install the Phoenix application generator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mix archive.install hex phx_new
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I only want to create an API and not use the views in Phoenix. So I do not want to generate the project with views and use webpack. I will use the corresponding options (for more info see &lt;a href="https://hexdocs.pm/phoenix/Mix.Tasks.Phx.New.html"&gt;here&lt;/a&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mix phx.new flashcards --no-html --no-webpack

Fetch and install dependencies? [Yn] y
    * running mix deps.get
  * running mix deps.compile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that our project is generated we can edit the database configuration in &lt;code&gt;config/dev.exs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Configure your database
config :flashcards, Flashcards.Repo,
  username: "geoffroy_baumier",
  password: "password",
  database: "flashcards_dev",
  hostname: "localhost",
  [...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can create the database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mix ecto.create
Compiling 11 files (.ex)
Generated flashcards app
The database for Flashcards.Repo has already been created
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good, now let's start the application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mix phx.server
[info] Running FlashcardsWeb.Endpoint with cowboy 2.8.0 at 0.0.0.0:4000 (http)
[info] Access FlashcardsWeb.Endpoint at http://localhost:4000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfect! If you want to see the project running, go to &lt;a href="http://localhost:4000/dashboard/home"&gt;http://localhost:4000/dashboard/home&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup the frontend
&lt;/h2&gt;

&lt;p&gt;Prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have NodeJS installed&lt;/li&gt;
&lt;li&gt;Choose a package manager, personally I use yarn&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we have our database and our API. As you see they already take two tabs of my terminal (dramatic tone, I could also just run in detached mode). We are only missing the frontend, let's jump into it without many details (more info &lt;a href="https://create-react-app.dev/docs/getting-started/"&gt;here&lt;/a&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ yarn create react-app my-app
$ yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the frontend is running on &lt;a href="http://localhost:3000/"&gt;http://localhost:3000/&lt;/a&gt;. And a third tab in my terminal is being used!&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Tilt
&lt;/h2&gt;

&lt;p&gt;Here come the best part, we can regroup and manage those resources all in one place using Tilt. Thanks to Tilt we can automate processes: start of the applications, watch for file changes, build our containers, watch the logs,...&lt;/p&gt;

&lt;p&gt;If you are using Homebrew you can install Tilt with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew install tilt-dev/tap/tilt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;For the magic to happen, I strongly suggest that you stop your container (even delete it), stop the Phoenix application and also the React application. Stop everything!&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Now let's create our Tiltfile at the root of the project.&lt;/p&gt;

&lt;p&gt;The first thing we want to do is create and start our database container. All I have to is reference the docker-compose file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker_compose('docker/docker-compose.yml')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then just below let's add our Phoenix application, I will call it 'api':&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;local_resource(
  'api',
  'cd backend &amp;amp;&amp;amp; mix deps.get',
  deps=['backend/config', 'backend/mix.exs', 'backend/mix.lock'],
  serve_cmd='cd backend &amp;amp;&amp;amp; mix phx.server',
  resource_deps=['postgres']
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go through the list of these parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first one is the name&lt;/li&gt;
&lt;li&gt;Then it is the command to be executed&lt;/li&gt;
&lt;li&gt;After we find the deps: which is &lt;em&gt;"a list of files or directories to be added as dependencies to this cmd. Tilt will watch those files and will run the cmd when they change."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Then we have the serve command which will be run on update&lt;/li&gt;
&lt;li&gt;And finally the resources of which this current resource depends on. As you can see we can directly reference the docker service.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are more parameters available: &lt;a href="//a%20list%20of%20resources%20on%20which%20this%20resource%20depends."&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And finally we can add our frontend:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;local_resource(
  'frontend',
  'cd frontend &amp;amp;&amp;amp; yarn install --frozen-lockfile',
  serve_cmd='cd frontend &amp;amp;&amp;amp; yarn start',
  deps=['frontend/package.json', 'frontend/yarn.lock'],
  resource_deps=['api']
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the whole Tiltfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker_compose('docker/docker-compose.yml')

local_resource(
  'api',
  'cd backend &amp;amp;&amp;amp; mix deps.get',
  serve_cmd='cd backend &amp;amp;&amp;amp; mix phx.server',
  deps=['backend/config', 'backend/mix.exs', 'backend/mix.lock'],
  resource_deps=['postgres']
)

local_resource(
  'frontend',
  'cd frontend &amp;amp;&amp;amp; yarn install --frozen-lockfile',
  serve_cmd='cd frontend &amp;amp;&amp;amp; yarn start',
  deps=['frontend/package.json', 'frontend/yarn.lock'],
  resource_deps=['api']
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run it we simply have to run this command in the root of our directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tilt up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And everything spins up and we have a nice interface to manage every individual service just in one place. I think that it's wonderful and I gladly recommand using it for local developement. It makes everything easier to start the whole stack with just one command. It also watches the files and does a reload. You can also manually reload a resource. And you have access to all the logs in one tab!&lt;/p&gt;

&lt;p&gt;Ho I almost forgot, to stop it you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tilt down
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;More info on managing local resources &lt;a href="https://docs.tilt.dev/local_resource.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>tilt</category>
      <category>docker</category>
      <category>elixir</category>
      <category>react</category>
    </item>
    <item>
      <title>Upgrading postgreSQL with Homebrew</title>
      <dc:creator>Geoff B.</dc:creator>
      <pubDate>Tue, 26 Jan 2021 21:01:11 +0000</pubDate>
      <link>https://dev.to/__geoff___/upgrading-postgresql-with-homebrew-33hp</link>
      <guid>https://dev.to/__geoff___/upgrading-postgresql-with-homebrew-33hp</guid>
      <description>&lt;p&gt;After upgrading a few programs including postgres when starting a new project, I ran into an issue. I already had some postgres databases from older projects and I couldn't start postgres (and create my new database).&lt;/p&gt;

&lt;p&gt;To install postgres with brew I used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew install postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see if postgres is running I can type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew services 
Name       Status  User Plist
postgresql stopped 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the funny thing was when I tried to start the service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew services start postgres
==&amp;gt; Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great! So it's running! But no..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew services
Name       Status  User             Plist
postgresql error   geoffroy_baumier /Users/geoffroy_baumier/Library/LaunchAgents/homebrew.mxcl.postgresql.plist               
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see what is the issue, let's look at the logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tail /usr/local/var/log/postgres.log
2021-01-26 21:12:47.678 CET [8757] FATAL:  database files are incompatible with server
2021-01-26 21:12:47.678 CET [8757] DETAIL:  The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 13.1.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there was the issue.&lt;br&gt;&lt;br&gt;
All I had to do to fix this was to run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew postgresql-upgrade-database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then let's start it postgres:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew services start postgres
==&amp;gt; Successfully started `postgresql` (label: homebrew.mxcl.postgresql)

$ brew services
Name          Status  User             Plist
postgresql    started geoffroy_baumier /Users/geoffroy_baumier/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
postgresql@12 stopped      
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No I can see that I have two postgres services with the two different versions. I can create my new updated database. Also the good thing is that I didn't lose any data from previous project and I can run the service with version 12 if I ever need it.&lt;/p&gt;

</description>
      <category>postgressql</category>
      <category>homebrew</category>
    </item>
  </channel>
</rss>
