-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (145 loc) · 5.05 KB
/
ci.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
157
158
159
160
161
162
163
164
165
name: CI
on:
push:
release:
types: [published]
workflow_dispatch:
inputs:
upload:
description: 'Upload the docker container'
required: false
default: false
type: boolean
redeploy:
description: 'Redeploy the container on pkg.toit.io'
required: false
default: false
type: boolean
redeploy-dev:
description: 'Redeploy the container on pkg-dev.toit.io'
required: false
default: false
type: boolean
env:
DOCKER_NAME: tpkg_registry
RAILWAY_PROJECT_ID: 6580ada5-829d-4c2a-8b84-0096bd87b421
RAILWAY_SERVICE_ID: d9ab2b13-9265-4757-97eb-282ac85f15fc
RAILWAY_DEV_SERVICE_ID: d22a4836-8f41-4d8b-b26c-bc16546e0738
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0 # Fetch the whole history.
# Use Go 1.17
- name: Switch to Go 1.17
uses: actions/setup-go@v5
with:
go-version: '^1.17.0'
- name: Go dependencies
run: |
make go_dependencies
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Build protobuf
run: |
make protobuf
- name: Build binary
run: |
make registry
- name: Test
run: |
make test
- name: Fetch dependencies
run: |
make image-dependencies
- name: Print known-hosts
run: |
ssh-keyscan github.com >> known_hosts
echo "You can use the following known_hosts file to add to your secrets"
cat known_hosts
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_NAME }}
# Generate Docker tags based on the following events/attributes.
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Print configuration
run: |
echo "DOCKER_NAME=${{ env.DOCKER_NAME }}"
echo "TAGS=${{ steps.meta.outputs.tags }}"
echo "LABELS=${{ steps.meta.outputs.labels }}"
- name: Login to GHCR
if: |
github.event.inputs.upload == 'true' ||
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
github.event_name == 'release'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: ${{
github.event.inputs.upload == 'true' ||
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
github.event_name == 'release' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: .
- name: Install Railway
if: |
github.event.inputs.redeploy == 'true' ||
github.event.inputs.redeploy-dev == 'true' ||
github.event_name == 'release' ||
(github.event_name == 'push' && github.ref == 'refs/heads/main')
run: npm i -g @railway/cli
- name: Deploy pkg-dev.toit.io
if: |
github.event.inputs.redeploy-dev == 'true' ||
(github.event_name == 'push' && github.ref == 'refs/heads/main')
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
# pkg-dev.toit.io is set up as follows:
# - Source image: ghcr.io/toitware/tpkg_registry:main
# - Variables:
# REGISTRY_BRANCH="main"
# REGISTRY_SSH_KEY="-----BEGIN OPENSSH PRIVATE KEY----- ... -----END OPENSSH PRIVATE KEY"
# REGISTRY_SSH_KEY_FILE="/secrets/ssh-key"
# REGISTRY_URL="github.com/toitware/registry"
run: |
railway link --project-id $RAILWAY_PROJECT_ID --service $RAILWAY_DEV_SERVICE_ID
railway redeploy -y
- name: Deploy pkg.toit.io
if: github.event.inputs.redeploy == 'true' || github.event_name == 'release'
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
# pkg.toit.io is set up as follows:
# - Source image: ghcr.io/toitware/tpkg_registry:latest
# - Variables:
# REGISTRY_BRANCH="main"
# REGISTRY_SSH_KEY="-----BEGIN OPENSSH PRIVATE KEY----- ... -----END OPENSSH PRIVATE KEY"
# REGISTRY_SSH_KEY_FILE="/secrets/ssh-key"
# REGISTRY_URL="github.com/toitware/registry"
run: |
railway link --project-id $RAILWAY_PROJECT_ID --service $RAILWAY_SERVICE_ID
railway redeploy -y