diff --git a/.github/workflows/dev-ci-cd.yml b/.github/workflows/dev-ci-cd.yml index 27cecc2..fd1e278 100644 --- a/.github/workflows/dev-ci-cd.yml +++ b/.github/workflows/dev-ci-cd.yml @@ -1,9 +1,9 @@ on: workflow_dispatch: - types: [ created ] + types: [created] push: branches: - - main + - main name: Dev deployment @@ -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 diff --git a/Cargo.toml b/Cargo.toml index c6d0f26..fcf9468 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,5 +49,5 @@ tokio = {version = "1", features = ["full"]} uuid = {version = "1.4.1", features = ["v4", "serde"]} [features] -default = ["spiritnet"] +default = [] spiritnet = [] diff --git a/Dockerfile b/Dockerfile index e4a7e95..375fc58 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 @@ -33,15 +34,15 @@ 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 @@ -49,13 +50,12 @@ 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"] \ No newline at end of file +CMD ["/app/attester-backend" , "/app/config.yaml"] diff --git a/docker-compose.yaml b/docker-compose.yaml index a148ab0..be1b779 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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: \ No newline at end of file