Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deploy-to-aws (#38) #39

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,4 +1,4 @@
FROM node:18-bookworm as build-stage

Check warning on line 1 in Dockerfile

View workflow job for this annotation

GitHub Actions / Deploy

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

RUN mkdir -p /workdir

Expand All @@ -10,12 +10,19 @@

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
Loading