ci: feat: add separate Dockerfile for FE and BE only

This commit is contained in:
2024-03-04 23:22:38 +01:00
parent 0f24f19c71
commit 22270f4bf7
4 changed files with 122 additions and 4 deletions
+64 -2
View File
@@ -9,10 +9,8 @@ on:
jobs:
ci-fe:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js 18.x
uses: actions/setup-node@v3
with:
@@ -68,6 +66,70 @@ jobs:
docker push registry.digitalocean.com/kemkas/kemkas:${GITHUB_SHA::8}
docker push ghcr.io/${{ github.repository_owner }}/kemkas:${GITHUB_SHA::8}
docker-fe-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DO_ACCESS_TOKEN }}
- name: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 1200
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- uses: docker/build-push-action@v5
with:
context: Kemkas.Web/frontend
file: Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
push: false
load: true
tags: kemkas/kemkas-fe:edge
- name: Tag container image
run: |
docker tag kemkas/kemkas-fe:edge registry.digitalocean.com/kemkas/kemkas-fe:${GITHUB_SHA::8}
docker tag kemkas/kemkas-fe:edge ghcr.io/${{ github.repository_owner }}/kemkas-fe:${GITHUB_SHA::8}
- name: Push image to Container Registry
run: |
docker push registry.digitalocean.com/kemkas/kemkas-fe:${GITHUB_SHA::8}
docker push ghcr.io/${{ github.repository_owner }}/kemkas-fe:${GITHUB_SHA::8}
docker-be-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DO_ACCESS_TOKEN }}
- name: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 1200
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- uses: docker/build-push-action@v5
with:
context: .
file: Kemkas.Web/Backend.Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
push: false
load: true
tags: kemkas/kemkas-be:edge
- name: Tag container image
run: |
docker tag kemkas/kemkas-be:edge registry.digitalocean.com/kemkas/kemkas-be:${GITHUB_SHA::8}
docker tag kemkas/kemkas-be:edge ghcr.io/${{ github.repository_owner }}/kemkas-be:${GITHUB_SHA::8}
- name: Push image to Container Registry
run: |
docker push registry.digitalocean.com/kemkas/kemkas-be:${GITHUB_SHA::8}
docker push ghcr.io/${{ github.repository_owner }}/kemkas-be:${GITHUB_SHA::8}
deploy:
runs-on: ubuntu-latest
needs:
+20
View File
@@ -0,0 +1,20 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["Kemkas.Web/Kemkas.Web.csproj", "Kemkas.Web/"]
RUN dotnet restore "Kemkas.Web/Kemkas.Web.csproj"
COPY . .
WORKDIR "/src/Kemkas.Web"
RUN dotnet build "Kemkas.Web.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Kemkas.Web.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Kemkas.Web.dll"]
+2 -2
View File
@@ -13,5 +13,5 @@ RUN yarn build
FROM nginx:latest as proxy
# COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder "/src/build" "/usr/share/nginx/html"
COPY --from=builder "/src/build" "/usr/share/nginx/html"
COPY ./nginx.conf /etc/nginx/nginx.conf
+36
View File
@@ -0,0 +1,36 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
}