-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (115 loc) · 4.15 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
on:
push:
branches:
- main
- staging
- expt
pull_request:
branches:
- main
- staging
# Trigger the workflow on release activity
release:
# Only use the types keyword to narrow down the activity types that will trigger your workflow.
types:
- published
- edited
- created
# Certain actions will only run when this is the main repo.
env:
MAIN_REPO: classtranscribe/latextranscribe
DOCKERHUB_ORG: classtranscribe
jobs:
docker:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
name:
- latextranscribe
include:
- name: latextranscribe-server
FOLDER: ./server
IMAGE: latextranscribe-server
DOCKERFILE: Dockerfile.cpu
steps:
- uses: actions/checkout@v2
# calculate some variables that are used later
- name: github branch
run: |
if [ "${{ github.event.release.target_commitish }}" != "" ]; then
BRANCH="${{ github.event.release.target_commitish }}"
else
BRANCH=${GITHUB_REF##*/}
fi
echo "GITHUB_BRANCH=${BRANCH}" >> $GITHUB_ENV
# Commit was for main/release branch, build a new version
if [ "$BRANCH" == "master" -o "$BRANCH" == "main" ]; then
version="$(cat gui/package.json | jq -r .version)"
echo "VERSION=$(version)" >> $GITHUB_ENV
tags="latest"
oldversion=""
while [ "${oldversion}" != "${version}" ]; do
oldversion="${version}"
tags="${tags},${version}"
version=${version%.*}
done
echo "TAGS=${tags}" >> $GITHUB_ENV
else
echo "VERSION=$BRANCH" >> $GITHUB_ENV
echo "TAGS=$BRANCH" >> $GITHUB_ENV
fi
# build the docker image, this will always run to make sure
# the Dockerfile still works.
- name: Build image
uses: elgohr/Publish-Docker-Github-Action@2.22
env:
BRANCH: ${{ env.GITHUB_BRANCH }}
VERSION: ${{ env.VERSION }}
BUILDNUMBER: ${{ github.run_number }}
GITSHA1: ${{ github.sha }}
with:
registry: docker.pkg.github.com
name: ${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ matrix.IMAGE }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
workdir: ${{ matrix.FOLDER }}
tags: "${{ env.TAGS }}"
dockerfile: ${{ matrix.DOCKERFILE }}
buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1
no_push: true
# TODO: need publish permissions for ghcr.io
# this will publish to github container registry
#- name: Publish to GitHub
# if: github.event_name != 'pull_request' && github.repository == env.MAIN_REPO
# uses: elgohr/Publish-Docker-Github-Action@2.22
# env:
# BRANCH: ${{ env.GITHUB_BRANCH }}
# VERSION: ${{ env.VERSION }}
# BUILDNUMBER: ${{ github.run_number }}
# GITSHA1: ${{ github.sha }}
# with:
# registry: ghcr.io
# name: ${{ github.repository_owner }}/${{ matrix.IMAGE }}
# username: ${{ secrets.GHCR_USERNAME }}
# password: ${{ secrets.GHCR_PASSWORD }}
# context: ${{ matrix.FOLDER }}
# tags: "${{ env.TAGS }}"
# buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1
# this will publish to dockerhub
- name: Publish to Docker Hub
if: github.event_name != 'pull_request' && github.repository == env.MAIN_REPO
uses: elgohr/Publish-Docker-Github-Action@2.22
env:
BRANCH: ${{ env.GITHUB_BRANCH }}
VERSION: ${{ env.VERSION }}
BUILDNUMBER: ${{ github.run_number }}
GITSHA1: ${{ github.sha }}
with:
name: ${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
workdir: ${{ matrix.FOLDER }}
tags: "${{ env.TAGS }}"
dockerfile: ${{ matrix.DOCKERFILE }}
buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1