Skip to content

Commit

Permalink
feat: Added Docker support (#22)
Browse files Browse the repository at this point in the history
* feat: Added Docker support

* ci: Added Docker workflow

* ci(docker.yml): Automatic tag

* ci(docker.yml): Changed deprecated outputs

* ci(docker.yml): Publishing to Docker Hub

* fix(docker.yml): Docker Hub image name

* fix(docker.yml): Usage of docker tag

Replacing with the build and push action
  • Loading branch information
FRFlo authored Mar 11, 2024
1 parent f63ea13 commit c02eaad
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
55 changes: 55 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build and push Docker image
on:
push:
branches:
- develop
- docker
paths:
- ".github/workflows/docker.yml"
- ".dockerignore"
- "Copy/**"

jobs:
build:
name: Build image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set variables
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "short_sha=$calculatedSha" >> $GITHUB_OUTPUT
echo "username=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.HUB_USERNAME }}
password: ${{ secrets.HUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Copy/Dockerfile
platforms: linux/amd64
push: true
tags: |
ghcr.io/${{ steps.vars.outputs.username }}:${{ steps.vars.outputs.short_sha }}
ghcr.io/${{ steps.vars.outputs.username }}:latest
${{ steps.vars.outputs.username }}:${{ steps.vars.outputs.short_sha }}
${{ steps.vars.outputs.username }}:latest
2 changes: 2 additions & 0 deletions Copy/Copy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
<PackageId>FRFlo.Copy</PackageId>
<Authors>FRFlo</Authors>
<Description>Copy software scoped for professional use</Description>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentFTP" Version="49.0.2" />
<PackageReference Include="Microsoft.Exchange.WebServices" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.15" />
<PackageReference Include="SSH.NET" Version="2024.0.0" />
Expand Down
23 changes: 23 additions & 0 deletions Copy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
USER app
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Copy/Copy.csproj", "Copy/"]
RUN dotnet restore "./Copy/Copy.csproj"
COPY . .
WORKDIR "/src/Copy"
RUN dotnet build "./Copy.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Copy.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Copy.dll"]

0 comments on commit c02eaad

Please sign in to comment.