forked from ras0q/go-backend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (78 loc) · 2.22 KB
/
image.yaml
File metadata and controls
81 lines (78 loc) · 2.22 KB
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
name: Build Docker Image
on:
workflow_dispatch:
push:
branches:
- main
tags:
- v*
pull_request:
branches:
- main
jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
CAN_PUSH: ${{ github.event_name != 'pull_request' && github.actor == github.repository_owner }}
steps:
- uses: actions/checkout@v5
- name: Generate Image Tags
uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/${{ github.repository }}
- name: Login to GitHub Container Registry
if: env.CAN_PUSH
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: ${{ env.CAN_PUSH }}
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# deploy branch にビルド済みの Docker image を参照する Dockerfile を作成するJob
# deploy という名前の orphan branch が事前に作られている必要がある
#
# ```sh
# git switch --orphan deploy
# git rm -rf .
# git push HEAD:deploy
# ```
#
# deploy:
# name: Deploy
# runs-on: ubuntu-latest
# needs: build
# if: github.event_name != 'pull_request'
# permissions:
# contents: write
# steps:
# - uses: actions/checkout@v5
# with:
# ref: deploy
# - name: Create Dockerfile for deploy
# run: printf "%s\n" "$DOCKERFILE" > Dockerfile
# env:
# DOCKERFILE: |
# FROM ghcr.io/${{ github.repository }}:${{ github.sha }}
# # 必要に応じて設定を追加する
# - name: Push empty commit
# run: |
# git config user.name "GitHub Actions"
# git config user.email "actions@github.com"
# git add Dockerfile
# git commit -m "Trigger deploy: ${{ github.ref }}"
# git push origin HEAD:deploy
# env:
# GITHUB_TOKEN: ${{ github.token }}
#