<?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>Forem: VictoriaMartinSahagun</title>
    <description>The latest articles on Forem by VictoriaMartinSahagun (@victoriamartinsahagun).</description>
    <link>https://forem.com/victoriamartinsahagun</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F986059%2F92c63350-36b7-4534-9162-f6d891ac4e31.jpeg</url>
      <title>Forem: VictoriaMartinSahagun</title>
      <link>https://forem.com/victoriamartinsahagun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/victoriamartinsahagun"/>
    <language>en</language>
    <item>
      <title>How to create automated Docker images for Vue apps using GitHub Actions</title>
      <dc:creator>VictoriaMartinSahagun</dc:creator>
      <pubDate>Wed, 07 Dec 2022 14:26:25 +0000</pubDate>
      <link>https://forem.com/victoriamartinsahagun/how-to-create-automated-docker-images-for-vue-apps-using-github-actions-1glo</link>
      <guid>https://forem.com/victoriamartinsahagun/how-to-create-automated-docker-images-for-vue-apps-using-github-actions-1glo</guid>
      <description>&lt;h2&gt;
  
  
  Content
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Add a Dockerfile&lt;/li&gt;
&lt;li&gt;Create a workflow&lt;/li&gt;
&lt;li&gt;Set up repository secrets&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Creating Docker images for your VueJS apps and pushing them to your Dockerhub account can be easily done using GitHub Actions.&lt;br&gt;
Here we will show you the steps to achieve it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Add a Dockerfile
&lt;/h2&gt;

&lt;p&gt;Once you have a VueJS app in a github repository, you will need to define a Dockerfile for GitHub to know how to build the Docker image. &lt;br&gt;
Add a Dockerfile in the root directory of your existing project, then add and commit the file to your GitHub repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a workflow
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to Actions and click in "set up a workflow yourself".
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq0l35u5ezdy6hx5um483.png" alt="Workflow" width="628" height="400"&gt;
&lt;/li&gt;
&lt;li&gt;Create the workflow in main.yml and commit the file.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Create image

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]
  workflow_dispatch:

jobs:
  Docker:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: setup git config
        run: |
          git config user.name "GitHub Actions Bot"
          git config user.email "&amp;lt;&amp;gt;"

      - name: Dependecies
        run: npm ci

      - name: Build
        run: npm run build

      - name: Push new version
        run: git push

      - name: Login to DockerHub Registry
        run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin

      - name: Build Docker image
        run: docker build . --file Dockerfile --tag victoriamartinsahagun/vueapp:latest
#replace victoriamartinsahagun with your DockerHub username
#replace vueapp with the image name

      - name: Push to Docker Hub
        run: docker push victoriamartinsahagun/vueapp:latest
#replace victoriamartinsahagun with your DockerHub username
#replace vueapp with the image name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Set up repository secrets.
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Login &lt;a href="https://hub.docker.com/" rel="noopener noreferrer"&gt;Docker Hub&lt;/a&gt;. If you don’t have an account you can &lt;a href="https://hub.docker.com/signup" rel="noopener noreferrer"&gt;sign up&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Go to your GitHub repository settings, look for "Secrets Actions" and click on “New repository secret”.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fprpf40khsdk6bkgl9b75.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fprpf40khsdk6bkgl9b75.png" alt="repository secret" width="716" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then add the following secrets:&lt;br&gt;
&lt;strong&gt;DockerHub Username&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name: DOCKERHUB_USERNAME&lt;/li&gt;
&lt;li&gt;Value: your Docker Hub username&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Docker Hub Password&lt;/strong&gt;&lt;br&gt;
For the password you will need to generate an Access Token in Docker Hub. Go to your Docker Hub account settings, click "Security" and crate a new Access Token.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzqnhmvicithofvzdp07a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzqnhmvicithofvzdp07a.png" alt="access token" width="700" height="273"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will open a new window, then copy the personal access token and paste it as the value of DOCKERHUB_PASSWORD secret.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7kec1aszeexy9izn29hj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7kec1aszeexy9izn29hj.png" alt="password" width="602" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations! Your GitHub repository is now configured to create new images and push them to Docker Hub everytime you make a push or create a pull request to it automatically!&lt;/p&gt;

&lt;h3&gt;
  
  
  Written by
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/gonzarl"&gt;Gonzalo Riquelme Ludwig&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/victoriamartinsahagun"&gt;Victoria Martin Sahagun&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>watercooler</category>
    </item>
  </channel>
</rss>
