diff --git a/.drone.yml b/.drone.yml index 95ed74b..574a6ad 100644 --- a/.drone.yml +++ b/.drone.yml @@ -56,4 +56,32 @@ steps: from_secret: db_password CODEFIRST_CLIENTDRONE_ENV_POSTGRES_DB: from_secret: db_database - ADMINS: erwanmenager,maximesapountzis,johnnyratton,victorgaborit,clementchieu \ No newline at end of file + ADMINS: erwanmenager,maximesapountzis,johnnyratton,victorgaborit,clementchieu + depends_on: [ tests ] + + # Build and push API image + - name: api-image-build-and-push + image: plugins/docker + settings: + dockerfile: docker/Dockerfile + context: API_SQLuedo/ + registry: hub.codefirst.iut.uca.fr + repo: hub.codefirst.iut.uca.fr/johnny.ratton/api_sqluedo + username: + from_secret: secret_registry_username + password: + from_secret: secret_registry_password + depends_on: [ deploy-sqluedo-db ] + + # Deploy API + - name: deploy-api-from-image + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest + environment: + IMAGENAME: hub.codefirst.iut.uca.fr/johnny.ratton/api_sqluedo + CONTAINERNAME: api-sqluedo + COMMAND: create + OVERWRITE: true + CODEFIRST_CLIENTDRONE_ENV_CONNECTION_STRING: + from_secret: connection_string + ADMINS: erwanmenager,maximesapountzis,johnnyratton,victorgaborit,clementchieu + depends_on: [ api-image-build-and-push ] \ No newline at end of file diff --git a/API_SQLuedo/DbContextLib/UserDbContext.cs b/API_SQLuedo/DbContextLib/UserDbContext.cs index 8c84706..b220b88 100644 --- a/API_SQLuedo/DbContextLib/UserDbContext.cs +++ b/API_SQLuedo/DbContextLib/UserDbContext.cs @@ -26,8 +26,8 @@ namespace DbContextLib base.OnConfiguring(optionsBuilder); if (!optionsBuilder.IsConfigured) { - //optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_STRING", EnvironmentVariableTarget.Process)); - optionsBuilder.UseNpgsql("Host=localhost;Database=SQLuedo;Username=admin;Password=motdepasse"); + optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_STRING", EnvironmentVariableTarget.Process)); + //optionsBuilder.UseNpgsql("Host=localhost;Database=SQLuedo;Username=admin;Password=motdepasse"); } } diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..c88caff --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,25 @@ +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +WORKDIR /api +EXPOSE 5000 + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /src +COPY ["../API_SQLuedo/API/API.csproj", "API_SQLuedo/"] + +# Restore dependencies +RUN dotnet restore "API_SQLuedo/API/API.csproj" + +# Copy the rest of the files +COPY "../API_SQLuedo/API/." "API_SQLuedo/" +WORKDIR "/src/API_SQLuedo" +RUN dotnet build "API.csproj" -c Release -o /app/build + +# Publish the application +FROM build AS publish +RUN dotnet publish "API.csproj" -c Release -o /app/publish + +# Final image +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "API.dll"] \ No newline at end of file