diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index f67a891..cc154a6 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -6,6 +6,9 @@ on: pull_request: branches: ["main"] +permissions: + packages: write + jobs: build-and-test: runs-on: ubuntu-latest @@ -29,3 +32,17 @@ jobs: - name: Build Docker image run: docker build -t bottomly . + + - name: Login to GitHub Container Registry + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Push image to GitHub Container Registry + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + run: | + docker tag bottomly ghcr.io/${{ github.repository }}:${{ github.sha }} + docker push ghcr.io/${{ github.repository }}:${{ github.sha }} diff --git a/.github/workflows/push_to_live.yml b/.github/workflows/push_to_live.yml index 9efa657..a2f4d8c 100644 --- a/.github/workflows/push_to_live.yml +++ b/.github/workflows/push_to_live.yml @@ -11,6 +11,8 @@ jobs: if: ${{ github.event.workflow_run.conclusion == 'success' }} environment: name: live + permissions: + packages: read steps: # checkout the repo - name: Checkout GitHub Action @@ -19,24 +21,21 @@ jobs: uses: azure/login@v1.4.5 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Build and push image - uses: azure/docker-login@v1 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 with: - login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }} - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} - - run: | - docker build . -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/bottomly:${{ github.sha }} - docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/bottomly:${{ github.sha }} + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Deploy to Azure Container Instances uses: azure/aci-deploy@v1 with: resource-group: ${{ secrets.RESOURCE_GROUP }} dns-name-label: ${{ secrets.RESOURCE_GROUP }}live${{ github.run_number }} - image: ${{ secrets.REGISTRY_LOGIN_SERVER }}/bottomly:${{ github.sha }} - registry-login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }} - registry-username: ${{ secrets.REGISTRY_USERNAME }} - registry-password: ${{ secrets.REGISTRY_PASSWORD }} + image: ghcr.io/${{ github.repository }}:${{ github.sha }} + registry-login-server: ghcr.io + registry-username: ${{ github.actor }} + registry-password: ${{ secrets.GITHUB_TOKEN }} name: bottomly-live location: uk south environment-variables: bottomly_giphy_api_key=${{ secrets.GIPHY_API_KEY }} diff --git a/Bottomly.AppHost/AppHost.cs b/Bottomly.AppHost/AppHost.cs index a60a1f3..1e74f12 100644 --- a/Bottomly.AppHost/AppHost.cs +++ b/Bottomly.AppHost/AppHost.cs @@ -9,7 +9,7 @@ .WithDataVolume() .WithLifetime(ContainerLifetime.Persistent); -var mongodb = mongo.AddDatabase("mongodb"); +var mongodb = mongo.AddDatabase("mongodb", "bottomly"); // var ollama = builder.AddOllama("ollama") // .WithEnvironment("OLLAMA_API_KEY", builder.Configuration["AppHost:OllamaApiKey"]) diff --git a/Bottomly/Program.cs b/Bottomly/Program.cs index ad7bedc..31c44d6 100644 --- a/Bottomly/Program.cs +++ b/Bottomly/Program.cs @@ -28,7 +28,10 @@ builder.Services.AddSingleton(sp => { var client = sp.GetRequiredService(); - return client.GetDatabase("bottomly"); + var configuration = sp.GetRequiredService(); + var connectionString = configuration.GetConnectionString("mongodb")!; + var databaseName = MongoUrl.Create(connectionString).DatabaseName ?? "bottomly"; + return client.GetDatabase(databaseName); }); // Configuration