From dee207d537e919dff6ba89fb067a481a8aa1c4c1 Mon Sep 17 00:00:00 2001 From: perezbhndavid <48489299+perezbhndavid@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:46:23 +0000 Subject: [PATCH] Crear workflow de deploy en azure --- .devcontainer/Dockerfile | 25 +++++++++++++++++ .devcontainer/devcontainer.json | 35 ++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 36 +++++++++++++++++++++++++ .github/dependabot.yml | 12 +++++++++ .github/workflows/create-deployment.yml | 24 +++++++++++++++++ package-lock.json | 2 +- src/components/Hours.js | 11 ++++++++ src/pages/index.js | 2 ++ 8 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/create-deployment.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..a7c44c1 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,25 @@ +FROM mcr.microsoft.com/devcontainers/javascript-node:1-22-bookworm + +# Install MongoDB command line tools - though mongo-database-tools not available on arm64 +ARG MONGO_TOOLS_VERSION=6.0 +RUN . /etc/os-release \ + && curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian ${VERSION_CODENAME}/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \ + && apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get install -y mongodb-mongosh \ + && if [ "$(dpkg --print-architecture)" = "amd64" ]; then apt-get install -y mongodb-database-tools; fi \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment if you want to install an additional version of node using nvm +# ARG EXTRA_NODE_VERSION=10 +# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" + +# [Optional] Uncomment if you want to install more global node modules +# RUN su node -c "npm install -g " + + + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..ddc1a66 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,35 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node-mongo +{ + "name": "Node.js & Mongo DB", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "mongodb.mongodb-vscode" + ] + } + }, + "features": { + "ghcr.io/devcontainers/features/azure-cli:1": {}, + "ghcr.io/devcontainers/features/github-cli:1": {} + } + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [3000, 27017], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "yarn install", + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..b7ba686 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,36 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + db: + image: mongo:latest + restart: unless-stopped + volumes: + - mongodb-data:/data/db + + # Uncomment to change startup options + # environment: + # MONGO_INITDB_ROOT_USERNAME: root + # MONGO_INITDB_ROOT_PASSWORD: example + # MONGO_INITDB_DATABASE: your-database-here + + # Add "forwardPorts": ["27017"] to **devcontainer.json** to forward MongoDB locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + +volumes: + mongodb-data: \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f33a02c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for more information: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://containers.dev/guide/dependabot + +version: 2 +updates: + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly diff --git a/.github/workflows/create-deployment.yml b/.github/workflows/create-deployment.yml new file mode 100644 index 0000000..d360301 --- /dev/null +++ b/.github/workflows/create-deployment.yml @@ -0,0 +1,24 @@ +name: Create Azure resources +on: [workflow_dispatch] +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + + # Checkout code + - uses: actions/checkout@main + + # Log into Azure + - uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + # Deploy Bicep file + - name: create resources + uses: azure/arm-deploy@v1 + with: + subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }} + resourceGroupName: ${{ vars.AZURE_RG }} + template: ${{ github.workspace }}/config/main.bicep + parameters: 'namePrefix=${{ vars.AZURE_PREFIX }}' + failOnStdErr: false \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c389731..5f782b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "template_modern_dev_Devops", + "name": "wth-devops", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/src/components/Hours.js b/src/components/Hours.js index d51ab5c..68e463f 100644 --- a/src/components/Hours.js +++ b/src/components/Hours.js @@ -1 +1,12 @@ // Placeholder to host a component +import React from 'react'; + +const HorarioAtencion = () => { + return ( +
+

10 a.m. a 4 p.m. de lunes a viernes, y de 9 a.m. a 8 p.m. los sábados y domingos

+
+ ); +}; + +export default HorarioAtencion; diff --git a/src/pages/index.js b/src/pages/index.js index a56f1e8..cd2d953 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -3,6 +3,7 @@ import dbConnect from "../lib/dbConnect"; import Pet from "../models/Pet"; // TODO: Import Hours component +import Hours from '../components/Hours'; const Index = ({ pets }) => { @@ -10,6 +11,7 @@ const Index = ({ pets }) => { <> {/* TODO: Display Hours component */} + {/* Create a card for each pet */} {pets.map((pet) => (