mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 00:19:00 +03:00
Add Dockerfile and compose.yaml (#335)
This PR adds Dockerfile, to run Octobot within a Docker container, and compose.yaml, to run the Octobot container along with any services that the user may require. --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> Signed-off-by: mctaylors <cantsendmails@mctaylors.ru> Co-authored-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
parent
9e44d49039
commit
84dc248038
4 changed files with 65 additions and 18 deletions
50
.github/workflows/build-push.yml
vendored
50
.github/workflows/build-push.yml
vendored
|
@ -8,29 +8,43 @@ on:
|
|||
branches: [ "master" ]
|
||||
|
||||
jobs:
|
||||
upload-solution:
|
||||
name: Upload Octobot to production
|
||||
upload-image:
|
||||
name: Upload Octobot Docker image
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
packages: write
|
||||
environment: production
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Publish solution
|
||||
run: dotnet publish $PUBLISH_FLAGS
|
||||
env:
|
||||
PUBLISH_FLAGS: ${{vars.PUBLISH_FLAGS}}
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
push: true
|
||||
tags: ghcr.io/${{vars.NAMESPACE}}/${{vars.IMAGE_NAME}}:latest
|
||||
build-args: |
|
||||
BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
|
||||
PUBLISH_OPTIONS=${{vars.PUBLISH_OPTIONS}}
|
||||
|
||||
update-production:
|
||||
name: Update Octobot on production
|
||||
runs-on: ubuntu-latest
|
||||
environment: production
|
||||
needs: upload-image
|
||||
|
||||
steps:
|
||||
- name: Setup SSH key
|
||||
run: |
|
||||
install -m 600 -D /dev/null ~/.ssh/id_ed25519
|
||||
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||||
ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts
|
||||
shell: bash
|
||||
shell: bash {0}
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}}
|
||||
SSH_HOST: ${{secrets.SSH_HOST}}
|
||||
|
@ -38,26 +52,26 @@ jobs:
|
|||
- name: Stop currently running instance
|
||||
run: |
|
||||
ssh $SSH_USER@$SSH_HOST $STOP_COMMAND
|
||||
shell: bash
|
||||
shell: bash {0}
|
||||
env:
|
||||
SSH_USER: ${{secrets.SSH_USER}}
|
||||
SSH_HOST: ${{secrets.SSH_HOST}}
|
||||
STOP_COMMAND: ${{vars.STOP_COMMAND}}
|
||||
|
||||
- name: Upload published solution
|
||||
- name: Update Docker image
|
||||
run: |
|
||||
scp -r $UPLOAD_FROM $SSH_USER@$SSH_HOST:$UPLOAD_TO
|
||||
shell: bash
|
||||
ssh $SSH_USER@$SSH_HOST docker pull ghcr.io/$NAMESPACE/$IMAGE_NAME:latest
|
||||
shell: bash {0}
|
||||
env:
|
||||
SSH_USER: ${{secrets.SSH_USER}}
|
||||
SSH_HOST: ${{secrets.SSH_HOST}}
|
||||
UPLOAD_FROM: ${{vars.UPLOAD_FROM}}
|
||||
UPLOAD_TO: ${{vars.UPLOAD_TO}}
|
||||
NAMESPACE: ${{vars.NAMESPACE}}
|
||||
IMAGE_NAME: ${{vars.IMAGE_NAME}}
|
||||
|
||||
- name: Start new instance
|
||||
run: |
|
||||
ssh $SSH_USER@$SSH_HOST $START_COMMAND
|
||||
shell: bash
|
||||
shell: bash {0}
|
||||
env:
|
||||
SSH_USER: ${{secrets.SSH_USER}}
|
||||
SSH_HOST: ${{secrets.SSH_HOST}}
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ riderModule.iml
|
|||
/.vs/
|
||||
GuildData/
|
||||
Logs/
|
||||
compose.yaml
|
||||
|
|
15
Dockerfile
Normal file
15
Dockerfile
Normal file
|
@ -0,0 +1,15 @@
|
|||
FROM mcr.microsoft.com/dotnet/sdk:8.0@sha256:35792ea4ad1db051981f62b313f1be3b46b1f45cadbaa3c288cd0d3056eefb83 AS build-env
|
||||
WORKDIR /Octobot
|
||||
|
||||
# Copy everything
|
||||
COPY . ./
|
||||
# Load build argument with publish options
|
||||
ARG PUBLISH_OPTIONS="-c Release"
|
||||
# Build and publish a release
|
||||
RUN dotnet publish ./TeamOctolings.Octobot $PUBLISH_OPTIONS -o out
|
||||
|
||||
# Build runtime image
|
||||
FROM mcr.microsoft.com/dotnet/runtime:8.0@sha256:a335dccd3231f7f9e2122691b21c634f96e187d3840c8b7dbad61ee09500e408
|
||||
WORKDIR /Octobot
|
||||
COPY --from=build-env /Octobot/out .
|
||||
ENTRYPOINT ["./TeamOctolings.Octobot"]
|
17
compose.example.yaml
Normal file
17
compose.example.yaml
Normal file
|
@ -0,0 +1,17 @@
|
|||
services:
|
||||
octobot:
|
||||
container_name: octobot
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
- PUBLISH_OPTIONS
|
||||
environment:
|
||||
- BOT_TOKEN
|
||||
volumes:
|
||||
- guild-data:/Octobot/GuildData
|
||||
- logs:/Octobot/Logs
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
guild-data:
|
||||
logs:
|
Loading…
Reference in a new issue