Skip to content

Commit

Permalink
feat: docker compose (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ad96el authored Jan 10, 2024
1 parent ec6bb89 commit a645103
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 85 deletions.
75 changes: 37 additions & 38 deletions .github/workflows/dev-ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
on:
workflow_dispatch:
types: [ created ]
types: [created]
push:
branches:
- main
- main

name: Dev deployment

Expand All @@ -14,43 +14,42 @@ jobs:
environment: dev

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
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: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
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@v2
with:
mask-password: 'true'
- name: Build image
run: |
docker build -t dena-attester:latest .
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: "true"
- name: Build image
run: |
docker build --build-arg BACKEND_URL=$BACKEND_URL --build-arg AUTH_URL=$AUTH_URL --build-arg BUILD_FEATURE="" -t dena-attester:latest .
- name: Tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dena/attester
IMAGE_TAG: ${{ github.sha }}
run: |
docker tag dena-attester $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker tag dena-attester $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
- name: Deploy to kilt cluster
uses: kodermax/kubectl-aws-eks@master
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dena/attester
IMAGE_TAG: ${{ github.sha }}
- name: Tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dena/attester
IMAGE_TAG: ${{ github.sha }}
run: |
docker tag dena-attester $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker tag dena-attester $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
- name: Deploy to kilt cluster
uses: kodermax/kubectl-aws-eks@master
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dena/attester
IMAGE_TAG: ${{ github.sha }}

with:
args: rollout restart deployment dena-attester -n dena-attester-dev

with:
args: rollout restart deployment dena-attester -n dena-attester-dev
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ tokio = {version = "1", features = ["full"]}
uuid = {version = "1.4.1", features = ["v4", "serde"]}

[features]
default = ["spiritnet"]
default = []
spiritnet = []
28 changes: 14 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Frontend Build Stage
FROM node:20.5.1 as frontend-build

ARG build_features=--no-default-features
ARG port=5656
ARG backend_url=http://localhost:5656/api/v1
ARG auth_url=http://localhost:4444/api/v1/authorize
ARG wss_endpoint=wss://peregrine.kilt.io:443/parachain-public-ws
ARG AUTH_URL=https://dev.opendid.kilt.io/api/v1/authorize
ARG BACKEND_URL=http://0.0.0.0:${port}/api/v1
ARG WSS_ENDPOINT=wss://peregrine.kilt.io:443/parachain-public-ws

ENV VITE_SIMPLE_REST_URL=${backend_url} \
VITE_AUTH_URL=${auth_url} \
VITE_WSS_ENDPOINT=${wss_endpoint}

ENV VITE_SIMPLE_REST_URL=${BACKEND_URL} \
VITE_AUTH_URL=${AUTH_URL} \
VITE_WSS_ENDPOINT=${WSS_ENDPOINT}

WORKDIR /usr/src/app

Expand All @@ -25,6 +24,8 @@ RUN yarn build
# Backend Build Stage
FROM rust:buster as backend-build

ARG BUILD_FEATURE=--features=spiritnet

RUN apt-get update && \
apt-get -y upgrade && \
apt-get -y install libpq-dev
Expand All @@ -33,29 +34,28 @@ WORKDIR /app

COPY . /app/

# Install sqlx-cli
RUN cargo install --root /app sqlx-cli

# Build backend
RUN cargo build --release ${build_features}
RUN cargo build --release --bin=attester-backend --package=attester-backend $BUILD_FEATURE

# Final Stage
FROM rust:slim-buster

ARG PORT=5656

WORKDIR /app

# Copy frontend build
COPY --from=frontend-build /usr/src/app/dist /usr/share/html

# Copy backend build
COPY --from=backend-build /app/target/release/attester-backend /app/attester-backend
COPY --from=backend-build /app/bin/sqlx /bin/sqlx

# Copy migrations and config
COPY /migrations /app/migrations
VOLUME /app/config.yaml

EXPOSE ${port}
EXPOSE ${PORT}

# Run migrations and start the application
CMD ["sh", "-c", "sqlx migrate run && /app/attester-backend /app/config.yaml"]
CMD ["/app/attester-backend" , "/app/config.yaml"]
44 changes: 12 additions & 32 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,45 +1,25 @@
version: '3'

services:
db:
image: postgres:latest
container_name: my_postgres
postgres:
image: postgres
environment:
POSTGRES_DB: attester
POSTGRES_USER: dena
POSTGRES_PASSWORD: secrect
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- '5432:5432'

backend:
image: kiltprotocol/attester:latest
build: .
container_name: my_backend
environment:
ATTESTER_DID_SEED: 'pave pattern upon invest humble squirrel cram flight wood travel already hint//did//0'
ATTESTER_ATTESTATION_SEED: 'pave pattern upon invest humble squirrel cram flight wood travel already hint//did//assertion//0'
PAYER_SEED: 'pave pattern upon invest humble squirrel cram flight wood travel already hint'
HOST_NAME: '0.0.0.0'
WSS_ADDRESS: 'wss://peregrine.kilt.io:443/parachain-public-ws'
DATABASE_URL: 'postgres://dena:secrect@db:5432/attester' # Updated database URL
RUST_LOG: 'info,debug,error,warn'
JWT_SECRET: 'super-secret-jwt-secret'
FRONT_END_PATH: '/usr/share/html'
PORT: 7777
- "5432:5432"
volumes:
- data:/var/lib/postgresql/data

depends_on:
- db
server:
build: ./
ports:
- '7777:7777' # Adjust the port as needed

opendid:
image: docker.io/kiltprotocol/opendid:latest
container_name: opendid
- "5656:5656"
depends_on:
- postgres
volumes:
- ./config.yaml:/app/config.yaml
ports:
- '3001:3001' # Adjust the port as needed

volumes:
postgres_data:
data:

0 comments on commit a645103

Please sign in to comment.