From 61e8ed3e3f41f95c01be7cc87a21d0814b1c1b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9on?= <111983295+lera005@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:28:45 +0100 Subject: [PATCH] feat: deploy-to-aws (#38) * feat: deploy-to-aws (#38) * refactor: rename ecr * refactor(terraform): rename version * fix: dockerfile --------- Co-authored-by: leonr6 Co-authored-by: codingluke Co-authored-by: robinb19 <111273003+robinb19@users.noreply.github.com> --- .github/workflows/deploy.yml | 10 ++++++---- Dockerfile | 9 ++++++++- docker-compose.yml | 8 +++++++- kamal/config/deploy.yml | 9 ++++----- nginx.conf | 6 +++--- terraform/main.tf | 4 ++-- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0ba1552..7c1b85a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,12 +3,13 @@ name: Deploy to Amazon AWS on: workflow_dispatch: + pull_request: push: - branches: ["main"] + branches: ['main'] env: AWS_REGION: us-east-1 - DOCKER_IMAGE_NAME: m324/nginx + DOCKER_IMAGE_NAME: m324/insimodus permissions: contents: read @@ -58,8 +59,8 @@ jobs: working-directory: kamal env: KAMAL_SERVER_IP: ${{ env.SERVER_IP }} - KAMAL_REGISTRY: "not-used-to-push-envs" - KAMAL_REGISTRY_PASSWORD: "not-used-to-push-envs" + KAMAL_REGISTRY: 'not-used-to-push-envs' + KAMAL_REGISTRY_PASSWORD: 'not-used-to-push-envs' run: | EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) to_envs() { jq -r "( . // {} ) | to_entries[] | \"\(.key)<<$EOF\n\(.value)\n$EOF\n\""; } @@ -95,5 +96,6 @@ jobs: KAMAL_REGISTRY_PASSWORD: ${{ steps.login-ecr.outputs[format('docker_password_{0}_dkr_ecr_us_east_1_amazonaws_com', secrets.AWS_ACCOUNT_ID)] }} VERSION: ${{ steps.meta.outputs.version }} run: | + bundle exec kamal traefik reboot -y bundle exec kamal deploy --skip-push --version=$VERSION echo "Visit me on [http://$KAMAL_SERVER_IP](http://$KAMAL_SERVER_IP) 🚀" >> $GITHUB_STEP_SUMMARY diff --git a/Dockerfile b/Dockerfile index 08712a3..236f087 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,12 +10,19 @@ RUN npm i RUN npm run build -FROM nginx:1.27.2-alpine +FROM ubuntu:24.10 LABEL service="insimodus" +# Install Nginx +RUN apt-get -y update\ + && apt-get -y install nginx git curl --no-install-recommends\ + && rm -rf /var/lib/apt/lists/* + COPY --from=build-stage /workdir/dist/ /usr/share/nginx/html COPY ./nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 3000/tcp + +CMD ["/usr/sbin/nginx", "-g", "daemon off;"] diff --git a/docker-compose.yml b/docker-compose.yml index 399af17..db059c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,12 @@ services: # DO NOT REMOVE THE MAPPER FOR LOCALHOST (127.0.0.1) # IF YOU DO IT YOU MIGHT GET HACKED # *************************************************** - - "127.0.0.1:5173:5173" + - '127.0.0.1:5173:5173' volumes: - .:/workspace:cached + production: + build: + context: . + dockerfile: Dockerfile + ports: + - '3000:3000' diff --git a/kamal/config/deploy.yml b/kamal/config/deploy.yml index fec6919..4d29d30 100644 --- a/kamal/config/deploy.yml +++ b/kamal/config/deploy.yml @@ -2,10 +2,10 @@ # Name of your application. Used to uniquely configure containers. # INFO: muss gleich sein zum Label "service" des zu deployende Dockerfile # siehe: `../../nginx/Dockerfile` -service: nginx +service: insimodus # Name of the container image. -image: m324/nginx +image: m324/insimodus # Deploy to these servers. servers: @@ -13,7 +13,7 @@ servers: hosts: - <%= ENV.fetch('KAMAL_SERVER_IP') %> options: - network: "kamal" # INFO: needs `docker network create kamal` on the servers! + network: 'kamal' # INFO: needs `docker network create kamal` on the servers! # Credentials for your image host. registry: @@ -34,13 +34,12 @@ ssh: # Configure custom arguments for Traefik. Be sure to reboot traefik when you modify it. traefik: options: - network: "kamal" # INFO: needs `docker network create kamal` on the servers! + network: 'kamal' # INFO: needs `docker network create kamal` on the servers! # Configure a custom healthcheck (default is /up on port 3000) healthcheck: path: /up port: 3000 - # Inject ENV variables into containers (secrets come from .env). # Remember to run `kamal env push` after making changes! # INFO: Uncomment to add mysql to the server diff --git a/nginx.conf b/nginx.conf index 1e19fdf..a10a2fc 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,15 +1,15 @@ server { listen 3000 default_server; listen [::]:3000 default_server; - + root /usr/share/nginx/html; index index.html index.htm; server_name _; location / { - try_files $uri /index.html; + try_files $uri /index.html; } - + location /up { return 200 'OK'; add_header Content-Type text/plain; diff --git a/terraform/main.tf b/terraform/main.tf index ad064d6..19f0b35 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -1,7 +1,7 @@ # General ------------------ terraform { - required_version = "~> 1.9.2" + # required_version = "~> 1.9.2" required_providers { aws = { source = "hashicorp/aws" @@ -130,7 +130,7 @@ output "ubuntu2404_public_ip" { # INFO : https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository resource "aws_ecr_repository" "myecr" { - name = "m324/nginx" + name = "m324/insimodus" image_tag_mutability = "MUTABLE" encryption_configuration { encryption_type = "KMS"