Add Dockerfile and compose.yaml (#335) #195
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Publish and deploy" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
on: | |
push: | |
branches: [ "master" ] | |
jobs: | |
upload-container: | |
name: Upload Octobot Docker container | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
environment: production | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Build container | |
run: docker buildx build --build-arg PUBLISH_OPTIONS="$PUBLISH_OPTIONS" -t $NAMESPACE/$IMAGE_NAME -f Dockerfile . | |
shell: bash | |
env: | |
PUBLISH_OPTIONS: ${{vars.PUBLISH_OPTIONS}} | |
NAMESPACE: ${{vars.NAMESPACE}} | |
IMAGE_NAME: ${{vars.IMAGE_NAME}} | |
- name: Push container | |
run: | | |
echo $CR_PAT | docker login ghcr.io -u $REPO_OWNER --password-stdin | |
docker push ghcr.io/$NAMESPACE/$IMAGE_NAME:latest | |
shell: bash | |
env: | |
CR_PAT: ${{secrets.GITHUB_TOKEN}} | |
REPO_OWNER: ${{github.repository_owner}} | |
NAMESPACE: ${{vars.NAMESPACE}} | |
IMAGE_NAME: ${{vars.IMAGE_NAME}} | |
upload-solution: | |
name: Upload Octobot to production | |
runs-on: ubuntu-latest | |
environment: production | |
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 | |
env: | |
SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}} | |
SSH_HOST: ${{secrets.SSH_HOST}} | |
- name: Stop currently running instance | |
run: | | |
ssh $SSH_USER@$SSH_HOST $STOP_COMMAND | |
shell: bash | |
env: | |
SSH_USER: ${{secrets.SSH_USER}} | |
SSH_HOST: ${{secrets.SSH_HOST}} | |
STOP_COMMAND: ${{vars.STOP_COMMAND}} | |
- name: Update Docker image | |
run: | | |
ssh $SSH_USER@$SSH_HOST docker pull ghcr.io/$NAMESPACE/$IMAGE_NAME:latest | |
shell: bash | |
env: | |
SSH_USER: ${{secrets.SSH_USER}} | |
SSH_HOST: ${{secrets.SSH_HOST}} | |
NAMESPACE: ${{vars.NAMESPACE}} | |
IMAGE_NAME: ${{vars.IMAGE_NAME}} | |
- name: Start new instance | |
run: | | |
ssh $SSH_USER@$SSH_HOST $START_COMMAND | |
shell: bash | |
env: | |
SSH_USER: ${{secrets.SSH_USER}} | |
SSH_HOST: ${{secrets.SSH_HOST}} | |
START_COMMAND: ${{vars.START_COMMAND}} |