parent
c674703428
commit
8b22c4ae0c
@ -0,0 +1,74 @@
|
|||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: "CI and deploy on iqball.maxou.dev"
|
||||||
|
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
|
name: "CI"
|
||||||
|
commands:
|
||||||
|
- dotnet test
|
||||||
|
|
||||||
|
- image: plugins/docker
|
||||||
|
name: "build and push docker image"
|
||||||
|
depends_on:
|
||||||
|
- "CI"
|
||||||
|
settings:
|
||||||
|
dockerfile: ci/API.dockerfile
|
||||||
|
context: .
|
||||||
|
registry: hub.codefirst.iut.uca.fr
|
||||||
|
repo: hub.codefirst.iut.uca.fr/maxime.batista/iqball-api-dotnet
|
||||||
|
tags:
|
||||||
|
- ${DRONE_BRANCH}
|
||||||
|
username:
|
||||||
|
from_secret: SECRET_REGISTRY_USERNAME
|
||||||
|
password:
|
||||||
|
from_secret: SECRET_REGISTRY_PASSWORD
|
||||||
|
|
||||||
|
# deploy staging database and server on codefirst
|
||||||
|
- image: eeacms/rsync:latest
|
||||||
|
name: "Instantiate docker images on staging server"
|
||||||
|
depends_on:
|
||||||
|
- "build and push docker image"
|
||||||
|
environment:
|
||||||
|
PRIVATE_KEY:
|
||||||
|
from_secret: PRIVATE_KEY
|
||||||
|
commands:
|
||||||
|
- mkdir -p ~/.ssh
|
||||||
|
- echo "$PRIVATE_KEY" > ~/.ssh/id_rsa
|
||||||
|
- chmod 0600 ~/.ssh
|
||||||
|
- chmod 0500 ~/.ssh/id_rsa*
|
||||||
|
- rsync -avz -e "ssh -p 80 -o 'StrictHostKeyChecking=no'" ci/deploy_staging_server.sh iqball@maxou.dev:/srv/www/iqball/$DRONE_BRANCH
|
||||||
|
- ssh -p 80 -o 'StrictHostKeyChecking=no' iqball@maxou.dev "chmod +x /srv/www/iqball/$DRONE_BRANCH/deploy_staging_server.sh && /srv/www/iqball/$DRONE_BRANCH/deploy_staging_server.sh $DRONE_BRANCH"
|
||||||
|
|
||||||
|
# Deploy the production database and server on codefirst
|
||||||
|
- image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
|
||||||
|
name: "Instantiate dotnet api docker image on codefirst"
|
||||||
|
depends_on:
|
||||||
|
- "build and push docker image"
|
||||||
|
environment:
|
||||||
|
IMAGENAME: hub.codefirst.iut.uca.fr/maxime.batista/iqball-api-dotnet:master
|
||||||
|
CONTAINERNAME: iqball_production_dotnet_webserver
|
||||||
|
OVERWRITE: true
|
||||||
|
COMMAND: create
|
||||||
|
|
||||||
|
CODEFIRST_CLIENTDRONE_ENV_PGSQL_DSN:
|
||||||
|
from_secret: POSTGRES_DSN
|
||||||
|
ADMINS: maximebatista
|
||||||
|
|
||||||
|
- image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
|
||||||
|
name: "Instantiate pgsql database docker image on codefirst"
|
||||||
|
depends_on:
|
||||||
|
- "build and push docker image"
|
||||||
|
environment:
|
||||||
|
IMAGENAME: postgres
|
||||||
|
CONTAINERNAME: iqball_production_database
|
||||||
|
COMMAND: create
|
||||||
|
|
||||||
|
CODEFIRST_CLIENTDRONE_ENV_POSTGRES_PASSWORD:
|
||||||
|
from_secret: POSTGRES_PASSWORD
|
||||||
|
CODEFIRST_CLIENTDRONE_ENV_POSTGRES_USER:
|
||||||
|
from_secret: POSTGRES_USER
|
||||||
|
CODEFIRST_CLIENTDRONE_ENV_POSTGRES_DB:
|
||||||
|
from_secret: POSTGRES_DB
|
||||||
|
ADMINS: maximebatista
|
@ -0,0 +1,16 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS builder
|
||||||
|
|
||||||
|
WORKDIR /home/
|
||||||
|
|
||||||
|
ADD . .
|
||||||
|
|
||||||
|
RUN cd ./API && dotnet publish -c Release
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
|
||||||
|
|
||||||
|
WORKDIR /home/
|
||||||
|
|
||||||
|
COPY --from=builder /home/API/bin/Release/net8.0 /home/
|
||||||
|
|
||||||
|
#$PGSQL_DSN is an environment variable
|
||||||
|
ENTRYPOINT /home/API
|
@ -0,0 +1,15 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
|
|
||||||
|
|
||||||
|
WORKDIR /home/
|
||||||
|
|
||||||
|
RUN apt update && apt install git -y
|
||||||
|
|
||||||
|
RUN dotnet tool install --global dotnet-ef
|
||||||
|
ENV PATH="$PATH:/root/.dotnet/tools"
|
||||||
|
|
||||||
|
ADD --chmod=755 db-init.sh ./
|
||||||
|
|
||||||
|
|
||||||
|
ENTRYPOINT ./db-init.sh $BRANCH
|
||||||
|
|
@ -0,0 +1,13 @@
|
|||||||
|
set -xeu
|
||||||
|
|
||||||
|
git clone https://codefirst.iut.uca.fr/git/IQBall/Dotnet-WebAPI
|
||||||
|
|
||||||
|
cd Dotnet-WebAPI
|
||||||
|
|
||||||
|
git switch $1
|
||||||
|
|
||||||
|
|
||||||
|
(cd AppContext && rm -rf Migrations && dotnet ef migrations add iqball-postgres-db-mig)
|
||||||
|
(cd API && dotnet ef database update --project ../AppContext)
|
||||||
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
set -xeu
|
||||||
|
|
||||||
|
docker network create iqball_net
|
||||||
|
|
||||||
|
docker run -d \
|
||||||
|
--name nginx-iqball-proxy \
|
||||||
|
-v /srv/nginx/nginx-iqball-proxy.conf:/etc/nginx/conf.d/default.conf \
|
||||||
|
-p 8081:8080 \
|
||||||
|
--restart=always \
|
||||||
|
--network iqball_net \
|
||||||
|
nginx
|
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -exu
|
||||||
|
|
||||||
|
API_CONTAINER_NAME="iqball-api-dotnet-$1"
|
||||||
|
DB_CONTAINER_NAME="iqball-db-$1"
|
||||||
|
|
||||||
|
(docker stop "$API_CONTAINER_NAME" && docker rm "$API_CONTAINER_NAME") || true
|
||||||
|
|
||||||
|
docker run -d \
|
||||||
|
--name "$DB_CONTAINER_NAME" \
|
||||||
|
--restart=always \
|
||||||
|
--network iqball_net \
|
||||||
|
--env POSTGRES_PASSWORD=1234 \
|
||||||
|
--env POSTGRES_USER=iqball \
|
||||||
|
--env POSTGRES_DATABASE=iqball \
|
||||||
|
postgres || true #run the database container if it does not already exists
|
||||||
|
|
||||||
|
# apply migrations on database
|
||||||
|
docker run --rm -t \
|
||||||
|
--env PGSQL_DSN="Server=$DB_CONTAINER_NAME;Username=iqball;Password=1234;Database=iqball" \
|
||||||
|
--env BRANCH="$1" \
|
||||||
|
--network iqball_net \
|
||||||
|
iqball-db-init:latest
|
||||||
|
|
||||||
|
|
||||||
|
docker pull "hub.codefirst.iut.uca.fr/maxime.batista/iqball-api-dotnet:$1"
|
||||||
|
|
||||||
|
# run the API
|
||||||
|
docker run -d \
|
||||||
|
--name "$API_CONTAINER_NAME" \
|
||||||
|
--restart=always \
|
||||||
|
--network iqball_net \
|
||||||
|
--env PGSQL_DSN="Server=$DB_CONTAINER_NAME;Username=iqball;Password=1234;Database=iqball" \
|
||||||
|
"hub.codefirst.iut.uca.fr/maxime.batista/iqball-api-dotnet:$1"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
|||||||
|
set -xeu
|
||||||
|
|
||||||
|
BRANCH=$1
|
||||||
|
|
||||||
|
sudo docker build -t iqball-api-dotnet:$BRANCH -f ci/Dockerfile .
|
||||||
|
sudo docker tag iqball-api-dotnet:$BRANCH hub.codefirst.iut.uca.fr/maxime.batista/iqball-api-dotnet:$BRANCH
|
||||||
|
sudo docker login hub.codefirst.iut.uca.fr
|
||||||
|
sudo docker push hub.codefirst.iut.uca.fr/maxime.batista/iqball-api-dotnet:$BRANCH
|
Loading…
Reference in new issue