Skip to content

Commit

Permalink
Switch action to “docker” type
Browse files Browse the repository at this point in the history
Running action as “composite” works, but actions/setup-go@v5 action
cannot cache Go dependencies because go.sum is outside workspace:

> [debug]Ignore '/home/runner/work/_actions/artyom/update-cloudformation-stack/main/go.sum' since it is not under GITHUB_WORKSPACE.

Make this action rely on the prebuilt docker image instead.
  • Loading branch information
artyom committed Nov 22, 2024
1 parent 98b7804 commit cae346e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
.github
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build and publish docker image

on:
workflow_dispatch:
push:
branches: [main]

concurrency: publish

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
packages: write

steps:
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- uses: docker/build-push-action@v6
with:
push: true
platforms: |
linux/arm64
linux/amd64
tags: |
ghcr.io/artyom/update-cloudformation-stack:latest
outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=6,force-compression=true
cache-from: type=gha
cache-to: type=gha,mode=max
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM --platform=$BUILDPLATFORM public.ecr.aws/docker/library/golang:alpine AS builder
WORKDIR /app
ENV CGO_ENABLED=0 GOTOOLCHAIN=auto
COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG TARGETOS TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o main

FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/main /
ENTRYPOINT ["/main"]
15 changes: 6 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ inputs:
required: true

runs:
using: composite
steps:
- uses: actions/setup-go@v5
with:
go-version: 'stable'
cache-dependency-path: ${{ github.action_path }}/go.sum
- shell: bash
run: |
go run -C ${{ github.action_path }} . -stack=${{ inputs.stack }} -key=${{ inputs.key }} -value=${{ inputs.value }}
using: docker
image: docker://ghcr.io/artyom/update-cloudformation-stack:latest
args:
- '-stack=${{ inputs.stack }}'
- '-key=${{ inputs.key }}'
- '-value=${{ inputs.value }}'

0 comments on commit cae346e

Please sign in to comment.