Skip to content

Commit

Permalink
feat: deploy-to-aws (#38)
Browse files Browse the repository at this point in the history
* feat: deploy-to-aws (#38)

* refactor: rename ecr

* refactor(terraform): rename version

* fix: dockerfile

---------

Co-authored-by: leonr6 <[email protected]>
Co-authored-by: codingluke <[email protected]>
Co-authored-by: robinb19 <[email protected]>
  • Loading branch information
4 people authored Dec 9, 2024
1 parent b585677 commit 61e8ed3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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\""; }
Expand Down Expand Up @@ -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
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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;"]
8 changes: 7 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
9 changes: 4 additions & 5 deletions kamal/config/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# 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:
web:
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:
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# General ------------------

terraform {
required_version = "~> 1.9.2"
# required_version = "~> 1.9.2"
required_providers {
aws = {
source = "hashicorp/aws"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 61e8ed3

Please sign in to comment.