forked from AMeierDev/java-telegram-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (91 loc) · 3.46 KB
/
build_java_docker.yml
File metadata and controls
108 lines (91 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# This is a basic workflow to help you get started with Actions
name: Build Java BuildDepolyDocker Start Docker on Server
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches:
- main
- staging
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
- name: Build with Maven
run: mvn clean package
- uses: actions/upload-artifact@v4
with:
name: java.telegrambots.jar
path: target/
deploy:
name: Deploy to Docker and restart on Server
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Git branch name
id: git-branch-name
uses: EthanSK/git-branch-name-action@v1
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4.1.7
with:
name: java.telegrambots.jar
path: target/
- name: Set up qemu
id: qemu
uses: docker/setup-qemu-action@v2
with:
image: tonistiigi/binfmt:latest
platforms: linux/amd64,linux/arm64,linux/arm/v7
-
name: Inspect builder
run: |
echo "Name: ${{ steps.qemu.outputs.name }}"
echo "Endpoint: ${{ steps.qemu.outputs.endpoint }}"
echo "Status: ${{ steps.qemu.outputs.status }}"
echo "Flags: ${{ steps.qemu.outputs.flags }}"
echo "Platforms: ${{ steps.qemu.outputs.platforms }}"
-
name: start buildx container
run: docker buildx create --use
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: amgamen/chatbot:${{ env.GIT_BRANCH_NAME }}
- name: Create SSH key
id: create_ssh_key
run: |
mkdir -p ~/.ssh/
echo "$SSH_PRIVATE_KEY" > ~/private.key
sudo chmod 600 ~/private.key
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
shell: bash
env:
SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}}
SSH_KNOWN_HOSTS: ${{secrets.SSH_KNOWN_HOSTS}}
- name: start docker with ssh
run: ssh -i ~/private.key -p 19999 bigmama@bigamgamen.de 'docker remove -f bot-${{ env.GIT_BRANCH_NAME }} && docker image pull amgamen/chatbot:${{ env.GIT_BRANCH_NAME }} && docker run -d -v chatbotvol-${{ env.GIT_BRANCH_NAME }}:/opt/telegrambot/data --env-file ~/chatbot/env_${{ env.GIT_BRANCH_NAME }} --restart unless-stopped --name bot-${{ env.GIT_BRANCH_NAME }} amgamen/chatbot:${{ env.GIT_BRANCH_NAME }}'