This repository has been archived by the owner on Oct 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
96 lines (90 loc) · 2.75 KB
/
docker.yml
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
name: Docker CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
IMAGE_NAME: gateway
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# JDK
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 16
# Chmod
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# Build
- name: Build with Gradle
run: ./gradlew build
env:
USERNAME: ${{ github.actor }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Upload
- name: Save Artifacts
uses: actions/upload-artifact@v2
if: github.event_name == 'push'
with:
name: bootjar
path: build/libs/*.jar
docker:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
# Download
- name: Download Artifacts
uses: actions/download-artifact@v2
with:
name: bootjar
path: build/libs/
# Delete artifact
- name: Delete artifacts
uses: geekyeggo/delete-artifact@v1
with:
name: bootjar
# Build
- name: Docker Build
run: docker build . --file Dockerfile --tag $IMAGE_NAME
# Auth
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
# Push
- name: Push image
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
deploy:
name: deploy
runs-on: ubuntu-latest
needs: docker
if: github.event_name == 'push'
steps:
- name: Restart Stack
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.CLUSTER_SSH_HOST }}
username: ${{ secrets.CLUSTER_SSH_USER }}
key: ${{ secrets.CLUSTER_SSH_KEY }}
script: |
cd /opt/lindsey
docker-compose rm -sf gateway
docker rmi docker.pkg.github.com/lindseybot/gateway/gateway:latest
docker-compose up -d gateway