From 6c1827a3973e5b764d828612e9f3ee376b8526b0 Mon Sep 17 00:00:00 2001 From: Oleksandr Petreniuk Date: Tue, 2 Apr 2024 13:00:59 +0300 Subject: [PATCH] GitHub action to build and publish --- .github/workflows/build_img.yml | 66 +++++++++++++++++++++++++++++++++ Dockerfile | 17 +++++++++ 2 files changed, 83 insertions(+) create mode 100644 .github/workflows/build_img.yml create mode 100644 Dockerfile diff --git a/.github/workflows/build_img.yml b/.github/workflows/build_img.yml new file mode 100644 index 0000000..713f652 --- /dev/null +++ b/.github/workflows/build_img.yml @@ -0,0 +1,66 @@ +name: Build ARM image and Publish to ECR + +on: + push: + branches: + - develop + +env: + BUILD_PATH: '/app/build/' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.repository }} + ref: ${{ github.sha }} + + - name: Install .NET Core SDK + uses: actions/setup-dotnet@v2 + with: + dotnet-version: '7.0' + + - name: Login to NuGet registry + run: | + dotnet nuget add source -u "${{ secrets.NUGET_GITHUB_USER }}" \ + -p "${{ secrets.NUGET_GITHUB_TOKEN }}" \ + --store-password-in-clear-text \ + -n github "https://nuget.pkg.github.com/OSTOLEX-Technologies/index.json" + + - name: Restore packages + run: dotnet restore "castledice-matchmaker/castledice-matchmaker.csproj" + + - name: Create build directory + run: mkdir -p ${{ env.BUILD_PATH }} + + - name: Build project + run: dotnet build castledice-matchmaker/castledice-matchmaker.csproj -c Release -r linux-musl-arm64 -o ${{ env.BUILD_PATH }} + + - name: Copy service files + run: | + cp Dockerfile ${{ env.BUILD_PATH }} + cp appsettings.json ${{ env.BUILD_PATH }} + cp nlog.config ${{ env.BUILD_PATH }} + + - 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: ${{ secrets.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: /app/build/ + push: true + tags: ${{ steps.login-ecr.outputs.registry }}/castledice-matchmaker:latest + platforms: linux/arm64 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..62c7dfd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM 130936542519.dkr.ecr.eu-central-1.amazonaws.com/castledice-riptide_server:latest + +ARG NET_VERSION=7.0.14 +ENV ASPNET_VERSION=$NET_VERSION + +RUN apk --no-cache add gcompat + +COPY . /app/ +RUN cp /usr/share/dotnet/shared/Microsoft.NETCore.App/$NET_VERSION/*.so /app/ + +WORKDIR /app + +RUN chmod +x castledice-matchmaker + +EXPOSE 7777 + +CMD ["dotnet", "/app/castledice-matchmaker.dll"]