forked from Simon-Initiative/oli-torus
-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (135 loc) · 5.35 KB
/
package.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Package
on:
push:
branches:
- master
- hotfix-*
- prerelease-*
- nextgen-ux
# manually trigger a package build from the Actions tab
workflow_dispatch:
jobs:
amazon-linux:
runs-on: ubuntu-latest
outputs:
app_version: ${{ steps.info.outputs.app_version }}
sha_short: ${{ steps.info.outputs.sha_short }}
deploy_host: ${{ steps.info.outputs.deploy_host }}
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v2
- name: 🧾 Build info
id: info
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "app_version=$(cat mix.exs | grep version | sed -e 's/.*version: "\(.*\)",/\1/')" >> $GITHUB_OUTPUT
echo "deploy_host=$(echo tokamak.oli.cmu.edu)" >> $GITHUB_OUTPUT
echo "workspace=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# build (or retrieve from cache) the amazon-linux-builder image, used by the next step to build the release for Amazon Linux 2
- name: 🐳 Build amazon-linux-builder image
uses: docker/build-push-action@v5
with:
context: ./.github/actions/amazon-linux-builder
load: true
push: false
tags: amazon-linux-builder:local
cache-from: type=gha
cache-to: type=gha,mode=max
- name: 📦 Package for Amazon Linux
uses: ./.github/actions/amazon-linux-builder
with:
build-sha: ${{ steps.info.outputs.sha_short }}
- name: 🗜️ Zip it
run: |
mkdir oli-torus-releases
cd _build/prod/rel/oli
zip -r ../../../../oli-torus-releases/oli-${{ steps.info.outputs.app_version }}-${{ steps.info.outputs.sha_short }}.zip *
- name: ⬆️💽 Upload release to S3 archive
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks
env:
AWS_S3_BUCKET: "oli-torus-releases"
AWS_ACCESS_KEY_ID: ${{ secrets.SIMON_BOT_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.SIMON_BOT_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "us-east-2"
SOURCE_DIR: "oli-torus-releases"
container:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
app_version: ${{ steps.info.outputs.app_version }}
sha_short: ${{ steps.info.outputs.sha_short }}
deploy_host: ${{ steps.info.outputs.deploy_host }}
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v3
- name: 🔧 Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: 🧾 Build info
id: info
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "app_version=$(cat mix.exs | grep version | sed -e 's/.*version: "\(.*\)",/\1/')" >> $GITHUB_OUTPUT
- name: 🧾 Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/simon-initiative/oli-torus
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: 🔑 Log in to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# builds the official oli-torus app image
- name: 🐳 Docker Build and Push
uses: docker/build-push-action@v5
with:
context: .
push: true
build-args: APP_VERSION=${{ steps.info.outputs.app_version }}
SHA_SHORT=${{ steps.info.outputs.sha_short }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
check-auto-deploy:
name: Check AUTO_DEPLOY_ENABLED config
runs-on: ubuntu-latest
environment: tokamak.oli.cmu.edu
outputs:
enabled: ${{ steps.check_auto_deploy_enabled.outputs.enabled }}
steps:
- name: Check whether AUTO_DEPLOY_ENABLED is set to TRUE
id: check_auto_deploy_enabled
run: echo "enabled=$(if [ "${{ vars.AUTO_DEPLOY_ENABLED }}" == "TRUE" ] ; then echo true ; else echo false ; fi)" >> $GITHUB_OUTPUT
deployment:
runs-on: ubuntu-latest
environment: tokamak.oli.cmu.edu
needs: [amazon-linux, check-auto-deploy]
if: github.ref == 'refs/heads/master' && needs.check-auto-deploy.outputs.enabled == 'true'
steps:
- run: echo "deploying ${{ github.sha }} ${{ github.ref }} ${{ github.ref_name }} to ${{ needs.amazon-linux.outputs.deploy_host }}"
- name: 🚢💰 Deploy to test using SSH
uses: fifsky/ssh-action@master
if: ${{ github.ref == 'refs/heads/master' }}
with:
command: |
cd /torus
sh deploy.sh -r ${{ github.ref }} ${{ needs.amazon-linux.outputs.app_version }} ${{ needs.amazon-linux.outputs.sha_short }}
host: ${{ needs.amazon-linux.outputs.deploy_host }}
user: simon-bot
key: ${{ secrets.SIMON_BOT_PRIVATE_KEY}}
port: 44067