Skip to content

Commit

Permalink
ci(deploy): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
codingluke committed Oct 26, 2024
1 parent 73edbb6 commit aa954b0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
branches: ["main"]

env:
AWS_REGION: us-east-1 # set this to your preferred AWS region, e.g. us-west-1
ECR_REPOSITORY: m324/nginx # set this to your Amazon ECR repository name
AWS_REGION: us-east-1
DOCKER_IMAGE_NAME: m324/nginx

permissions:
contents: read
Expand Down Expand Up @@ -58,8 +58,8 @@ jobs:
working-directory: kamal
env:
KAMAL_SERVER_IP: ${{ env.SERVER_IP }}
KAMAL_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
KAMAL_REGISTRY_PASSWORD: ${{ steps.login-ecr.outputs[format('docker_password_{0}_dkr_ecr_us_east_1_amazonaws_com', secrets.AWS_ACCOUNT_ID)] }}
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 All @@ -75,7 +75,7 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}
${{ steps.login-ecr.outputs.registry }}/${{ env.DOCKER_IMAGE_NAME }}
tags: type=sha

- name: Build and push nginx Image
Expand All @@ -94,10 +94,4 @@ jobs:
KAMAL_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
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: |
# --skip-push tell kamal to not build the image
# --verbose more detailed logging
# --version=$IMAGE_TAG we set the tag to deploy which has been already pushed before
#
# bundle exec kamal setup --skip-push --version=$IMAGE_TAG
bundle exec kamal deploy --skip-push --version=$VERSION
run: bundle exec kamal deploy --skip-push --version=$VERSION
63 changes: 33 additions & 30 deletions kamal/config/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# yaml-language-server: $schema=https://json.schemastore.org/yamllint.json
# 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

# Name of the container image.
Expand All @@ -16,11 +18,28 @@ servers:
# Credentials for your image host.
registry:
# Specify the registry server, if you're not using Docker Hub
server: <%= ENV.fetch('KAMAL_REGISTRY') %>
server: <%= ENV['KAMAL_REGISTRY'] || 'not-defined' %>
username: AWS

# Always use an access token rather than real password when possible.
password: <%= ENV.fetch('KAMAL_REGISTRY_PASSWORD') %>
password: <%= ENV['KAMAL_REGISTRY_PASSWORD'] || 'not-defined' %>

hooks_path: ./hooks # path relative to where "kamal" command is run!

ssh:
user: ubuntu
# keys_only: true
# keys: ["~/.ssh/id_rsa.pem"]

# 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!

# 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!
Expand All @@ -32,25 +51,6 @@ registry:
# - MYSQL_PASSWORD
# - MYSQL_DATABASE

hooks_path: ./hooks # path relative to where "kamal" command is run!

ssh:
user: ubuntu
# keys_only: true
# keys: ["~/.ssh/id_rsa.pem"]

# Configure builder setup.
# builder:
# context: ../nginx
# dockerfile: ../nginx/Dockerfile
# args:
# RUBY_VERSION: 3.2.0
# secrets:
# - GITHUB_TOKEN
# remote:
# arch: amd64
# host: ssh://[email protected]

# Use accessory services (secrets come from .env).
# INFO: Uncomment to add mysql to the server
# Also add all envs as GitHub Environment vars.
Expand All @@ -72,12 +72,15 @@ ssh:
# directories:
# - data:/var/lib/mysql

# 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!

# Configure a custom healthcheck (default is /up on port 3000)
healthcheck:
path: /up
port: 3000
# INFO: Not used in our setup as we build isolated
# Configure builder setup.
# builder:
# context: ../nginx
# dockerfile: ../nginx/Dockerfile
# args:
# RUBY_VERSION: 3.2.0
# secrets:
# - GITHUB_TOKEN
# remote:
# arch: amd64
# host: ssh://[email protected]
2 changes: 2 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Pull the minimal Ubuntu image
FROM ubuntu:24.10

# INFO: Das label "service" muss gesetzt damit kamal deploy funktioniert
# Der Wert muss gleich sein wie der name `../kamal/config/deploy.yml`
LABEL service="nginx"

# Install Nginx
Expand Down

0 comments on commit aa954b0

Please sign in to comment.