Skip to content

Commit

Permalink
Merge pull request #201 from ueckoken/write-dockerfile
Browse files Browse the repository at this point in the history
state-managerのDockerfileを書いてActionsでghcrにプッシュするようにした
  • Loading branch information
Azuki-bar authored Nov 8, 2023
2 parents 56882db + 3fff4e6 commit 5d55526
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 11 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/publish-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: build and publish image

on:
push:
branches:
- "main"
- "deployment"
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
id: extract_branch

- name: Generate tag
id: generate_tag
shell: bash
run: echo "tag=$(echo ${{ github.sha }} | cut -c1-7)-$(date +%s)" >> $GITHUB_OUTPUT

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Bake images
uses: docker/bake-action@v4
env:
TAG: ${{ steps.generate_tag.outputs.tag }}
with:
files: ./docker-bake.hcl
push: ${{ github.event_name == 'push' && startsWith( steps.extract_branch.outputs.branch , 'deployment' ) }}
set: |
*.cache-from=type=local,src=/tmp/.buildx-cache
*.cache-to=type=local,mode=min,dest=/tmp/.buildx-cache-new
provenance: false

# https://github.com/docker/build-push-action/issues/252#issuecomment-744400434
- name: Move Cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
File renamed without changes.
11 changes: 0 additions & 11 deletions backend/state-manager/Dockerfile

This file was deleted.

File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
group "default" {
targets = [
"state-manager"
]
}

variable "PREFIX" {
default = "plarail2023"
}

variable "TAG" {
default = "latest"
}

function "GET_TAG" {
params = [image]
result = "ghcr.io/ueckoken/${PREFIX}-${image}:${TAG}"
}

target "state-manager" {
dockerfile = "docker/backend/state-manager/Dockerfile"
tags = [
GET_TAG("state-manager")
]
platforms = [
"linux/amd64",
"linux/arm64"
]
}
14 changes: 14 additions & 0 deletions docker/backend/state-manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM --platform=$BUILDPLATFORM golang:1.21-bookworm AS builder
WORKDIR /state-manager
ARG TARGETOS
ARG TARGETARCH
ENV GOOS=${TARGETOS}
ENV GOARCH=${TARGETARCH}
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN go build -o state-manager backend/state-manager/cmd/main.go

FROM --platform=$TARGETPLATFORM gcr.io/distroless/base-debian12:nonroot AS runner
COPY --from=builder /state-manager/state-manager /state-manager
ENTRYPOINT ["/state-manager"]

0 comments on commit 5d55526

Please sign in to comment.