Skip to content

Commit

Permalink
Add support for Docker and deploying to server
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenarakelyan committed Jul 29, 2024
1 parent 79fdba8 commit 0993a6f
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 34 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
RACK_ENV=production
GITHUB_CLIENT_ID=test
GITHUB_CLIENT_SECRET=test
GITHUB_USERNAME=test
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Deploy Docker image to server

on:
release:
types:
- released

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
deploy-image:
runs-on: ubuntu-latest
steps:
- name: Install SSH key
run: |
install -m 600 -D /dev/null ~/.ssh/id_ed25519
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
ssh-keyscan -H ${{ secrets.SSH_HOST }} > ~/.ssh/known_hosts
- name: Connect via SSH, pull repository and Docker image
run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "cd ${{ secrets.WORK_DIR }} && git pull && docker compose pull && docker compose up -d && exit"
- name: Clean up
run: rm -rf ~/.ssh
47 changes: 47 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Create and publish Docker image to GitHub Container Registry

on:
push:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.env
run.sh
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.0
3.3.4
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ruby:3.3.4 AS base
WORKDIR /app

COPY Gemfile Gemfile.lock ./

FROM base AS prod-deps
RUN bundle install --without development
COPY . .

EXPOSE 9292
CMD ["bundle", "exec", "puma"]
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
source "https://rubygems.org"

ruby "3.3.0"
ruby "3.3.4"

gem "addressable", "~> 2.8.6"
gem "dotenv", "~> 3.1.0"
gem "jwt", "~> 2.8.1"
gem "addressable", "~> 2.8.7"
gem "dotenv", "~> 3.1.2"
gem "jwt", "~> 2.8.2"
gem "omniauth", "~> 2.1.2"
gem "omniauth-github", "~> 2.0.1"
gem "puma", "~> 6.4.2"
Expand Down
60 changes: 33 additions & 27 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
diff-lcs (1.5.1)
dotenv (3.1.0)
faraday (2.9.0)
dotenv (3.1.2)
faraday (2.10.0)
faraday-net_http (>= 2.0, < 3.2)
faraday-net_http (3.1.0)
logger
faraday-net_http (3.1.1)
net-http
hashie (5.0.0)
json (2.7.2)
jwt (2.8.1)
jwt (2.8.2)
base64
language_server-protocol (3.17.0.3)
multi_xml (0.6.0)
logger (1.6.0)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
net-http (0.4.1)
uri
nio4r (2.7.1)
nio4r (2.7.3)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
jwt (>= 1.0, < 3.0)
Expand All @@ -39,15 +43,15 @@ GEM
omniauth-oauth2 (1.8.0)
oauth2 (>= 1.4, < 3)
omniauth (~> 2.0)
parallel (1.24.0)
parser (3.3.0.5)
parallel (1.25.1)
parser (3.3.4.0)
ast (~> 2.4.1)
racc
public_suffix (5.0.5)
public_suffix (6.0.1)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.7.3)
rack (3.0.10)
racc (1.8.0)
rack (3.1.7)
rack-protection (4.0.0)
base64 (>= 0.1.0)
rack (>= 3.0.0, < 4)
Expand All @@ -59,34 +63,35 @@ GEM
rack (>= 3)
webrick (~> 1.8)
rainbow (3.1.1)
regexp_parser (2.9.0)
rexml (3.2.6)
regexp_parser (2.9.2)
rexml (3.3.2)
strscan
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
rspec-expectations (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.63.3)
rubocop (1.65.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sinatra (4.0.0)
Expand All @@ -98,7 +103,8 @@ GEM
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
tilt (2.3.0)
strscan (3.1.0)
tilt (2.4.0)
unicode-display_width (2.5.0)
uri (0.13.0)
version_gem (1.1.4)
Expand All @@ -109,9 +115,9 @@ PLATFORMS
ruby

DEPENDENCIES
addressable (~> 2.8.6)
dotenv (~> 3.1.0)
jwt (~> 2.8.1)
addressable (~> 2.8.7)
dotenv (~> 3.1.2)
jwt (~> 2.8.2)
omniauth (~> 2.1.2)
omniauth-github (~> 2.0.1)
puma (~> 6.4.2)
Expand All @@ -122,7 +128,7 @@ DEPENDENCIES
sinatra (~> 4.0.0)

RUBY VERSION
ruby 3.3.0p0
ruby 3.3.4p94

BUNDLED WITH
2.5.7
2.5.11
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It is currently used by me on the [wackomenace](https://www.wackomenace.co.uk) w

## Quick start (local development)

Ensure Ruby 3.3.0 is installed. Then run:
Ensure Ruby 3.3.4 is installed. Then run:

```
cp .env.example .env
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: authmenace

services:
web:
image: ghcr.io/rubenarakelyan/authmenace:main
env_file: .env
ports:
- "4002:9292"
restart: always

0 comments on commit 0993a6f

Please sign in to comment.