-
Notifications
You must be signed in to change notification settings - Fork 3
63 lines (61 loc) · 2.3 KB
/
pr-preview-env.yaml
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
name: Pull Request Preview Environment
on:
pull_request:
types: [labeled, synchronize, opened, reopened]
jobs:
build-preview-image:
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'preview') }}
env:
CLIENT_IMAGE_REPO: ghcr.io/elifesciences/enhanced-preprints-client
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build preview image
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
target: prod
platforms: linux/amd64,linux/arm64
tags: |
${{ env.CLIENT_IMAGE_REPO }}:preview-${{ github.event.number }}
- name: load preview image
uses: docker/build-push-action@v5
with:
context: .
target: prod
platforms: linux/amd64
load: true
tags: |
${{ env.CLIENT_IMAGE_REPO }}:preview-${{ github.event.number }}
- name: run image
run: docker run --rm -d --name "test_preview" -p 3000:3000 ${{ env.CLIENT_IMAGE_REPO }}:preview-${{ github.event.number }}
- name: test /status endpoint
run: curl --retry-all-errors --retry 5 http://localhost:3000/status
- name: clean up running image
run: docker stop test_preview
- name: Get current date
id: date
run: echo "date=$(date --utc +%Y%m%d.%H%M)" >> $GITHUB_OUTPUT
- name: Push preview image
uses: docker/build-push-action@v5
with:
context: .
target: prod
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.CLIENT_IMAGE_REPO }}:preview-${{ github.event.number }}
${{ env.CLIENT_IMAGE_REPO }}:preview-${{ github.event.number }}-${{ github.event.pull_request.head.sha }}
${{ env.CLIENT_IMAGE_REPO }}:preview-${{ github.event.number }}-${{ github.event.pull_request.head.sha }}-${{ steps.date.outputs.date }}