Skip to content

Commit

Permalink
Docker - Client and common compose (#20)
Browse files Browse the repository at this point in the history
* Simple Dockerfile for client

* Client Docker image is Done & Neat

* Svelte installed as normal dep :(

No audit during build

* Moving compose out, .dockerignores

* Images workflow for Docker images & ECR

* Adding DEV.md to trigger build

* Updating aws region

* Setting up dependant CI jobs

* Depend on server test suite

* Fixing multi file COPY-ies

* Docker image publish only from main branch

* Some more to README, whitespaces

* Readme tweak

* Fixing a silly link in readme

* New packege-lock after merge

* One more readme link try

* Directly using Vite for build and package

sveltejs/kit#5184

* Adding node 18 workflow

Skipping workflows not related to the PR

* Remove test workflow config

omit=dev in client dockerfile
  • Loading branch information
djavorek authored Jul 9, 2022
1 parent 424a00f commit 8df67da
Show file tree
Hide file tree
Showing 17 changed files with 1,767 additions and 1,795 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Build & Publish Docker Images

on:
push:
branches: ["main"]
workflow_dispatch:

jobs:
publish-client:
name: Publish Client image
runs-on: ubuntu-latest

steps:
- name: Wait for Client checks to succeed
uses: lewagon/[email protected]
with:
ref: ${{ github.ref }}
check-name: "Build and Check Client (18.x)"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check out code
uses: actions/checkout@v2

- name: Authenticate into AWS
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-central-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Client - Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: rezsi-client
IMAGE_TAG: latest
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./client
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
publish-server:
name: Publish Server image
runs-on: ubuntu-latest

steps:
- name: Wait for Server checks to succeed
uses: lewagon/[email protected]
with:
ref: ${{ github.ref }}
check-name: "Server Test Suite"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check out code
uses: actions/checkout@v2

- name: Authenticate into AWS
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-central-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Server - Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: rezsi-server
IMAGE_TAG: latest
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./server
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
8 changes: 5 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ on:
branches: ["main"]
pull_request:
branches: ["**"]
paths:
- "server/**"
workflow_dispatch:

name: Rust CI
Expand All @@ -12,7 +14,7 @@ env:

jobs:
check:
name: Check
name: Server Check
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand All @@ -32,7 +34,7 @@ jobs:
args: --manifest-path server/Cargo.toml

test:
name: Test Suite
name: Server Test Suite
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand All @@ -52,7 +54,7 @@ jobs:
args: --manifest-path server/Cargo.toml

lints:
name: Lints
name: Server Lints
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/svelte.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ on:
branches: ["main"]
pull_request:
branches: ["**"]
paths:
- "client/**"
workflow_dispatch:

jobs:
build:
name: Build and Check Client
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./client/

strategy:
matrix:
node-version: [16.x]
node-version: [16.x, 18.x]

steps:
- name: Checkout repository
Expand Down
36 changes: 36 additions & 0 deletions DEV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Backend dev setup
## Prerequisites
- rustup
- Docker / MySQL / PostgreSQL

## Starting a dev database
- There are two options:
- local mysql database
- Run the `server/init.sql` file, which creates the necessary database structure
- mysql database in a docker container with docker-compose
- Run `docker-compose up -d database` and a database will be available at the 3306 port, already initialized

## Running server
- Build and run with `cargo run`, it will automatically run database migrations
- When developing use `cargo watch -x run` for hot-reloading, provided `cargo-watch` is installed
- To manipulate migrations, refer to the README.md in the `server/migration` directory and use the CLI tool
- It uses the outer `.env` file for the connection string but it can be supplied with it's own file in the `server/migration` directory if needed

# Frontend dev setup
## Prerequisites
- Docker
- node 16.7 or higher
- v16.14.0 ✅
- v18.4.0 ✅
- npm v7 or higher
- 8.4.1 ✅

## Starting backend for client
- To run the complete backend (database & server), use `docker-compose up -d database server`, the database will be available at port 3306 and the server on 8000
- The build will take some time at first and on changes, consequent runs will be much faster thanks to docker caching
- It can be used as a backend for frontend development, the server is built in release mode, so it is smaller and highly optimized

## Starting Svelte dev server
- `cd ./client`
- `npm i`
- `npm run dev`
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
# veryrezsi
# 💲 VeryRezsi 💲
###### Status
![Docker Build](https://github.com/szattila98/veryrezsi/actions/workflows/images.yml/badge.svg)
## Brief
Subscription and expense calculator web-application.

# Usage

## Prerequisites

- npm v7 or higher
- 8.4.1 ✅
- node v14 or higher
- v16.14.0 ✅
Powered by SvelteKit on client side, and Rust on server side.

## Development
- `cd ./veryrezsi/client`
- `npm i`
- `npm run dev`
Refer to [DEV.md](../main/DEV.md) file.
8 changes: 8 additions & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Dockerfile
.dockerignore
.gitignore
*/node_modules
*/npm-debug.log
.svelte-kit
build
README.md
22 changes: 22 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Stage BUILD
FROM node:18-alpine

WORKDIR /app
COPY . ./

RUN npm ci --no-audit
RUN npm run build

# Stage RUN
FROM node:18-alpine

WORKDIR /app

COPY --from=0 /app/package*.json ./
COPY --from=0 /app/build ./

# clean install dependencies, no devDependencies, no prepare script
RUN npm ci --omit=dev --ignore-scripts --no-audit

EXPOSE 3000
CMD ["node", "./index.js"]
Loading

0 comments on commit 8df67da

Please sign in to comment.