-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (67 loc) · 2.86 KB
/
docker-images.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
name: Docker Images
on:
push:
branches:
- main
pull_request:
merge_group:
jobs:
build_api:
name: Build (api)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf # v3.1.0
with:
dockerfile: Dockerfile
- uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3
- uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: image_tag
name: Determine image tag
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
result-encoding: string
script: |
if (context.eventName === "push" && context.ref.startsWith("refs/tags/v"))
return context.ref.substring(11)
else if (context.eventName === "push" && context.ref === "refs/heads/main")
return "latest"
else
return context.sha
# pull_requestではcontext.shaすなわちGITHUB_SHAの値には若干違う値が入るが支障はないので無視する.
# ref: https://sue445.hatenablog.com/entry/2021/01/07/004835
- uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: Dockerfile
push: ${{ github.event_name == 'push' }}
tags: ghcr.io/${{ github.repository_owner }}/api:${{ steps.image_tag.outputs.result }}
build_migration:
name: Build (api-postgres-migration)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
- uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf # v3.1.0
with:
dockerfile: Dockerfile.migration
- uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 # v2
- uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: echo "LATEST_MIGRATION_NAME=$(ls -1 --ignore migration_lock.toml ./prisma/migrations --reverse | head -n 1)" >> $GITHUB_ENV
- uses: docker/build-push-action@0a97817b6ade9f46837855d676c4cca3a2471fc9 # v4
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: Dockerfile.migration
push: ${{ github.event_name == 'push' }}
tags: ghcr.io/${{ github.repository_owner }}/api-postgres-migration:${{ env.LATEST_MIGRATION_NAME }}