Skip to content

Exporting ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL to enable the Docker layer caching on GitHub Actions.

License

Notifications You must be signed in to change notification settings

peaceiris/actions-export-envs

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

actions-export-envs

This action exports ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL to enable the Docker layer caching on GitHub Actions.

cf. GitHub Actions cache | Docker Documentation

Usage

Example:

DOCKER_CLI_EXPERIMENTAL := enabled
DOCKER_BUILDKIT := 1
DOCKER_SCOPE := action-image-${GITHUB_REF_NAME}

PKG_NAME := ghcr.io/peaceiris/actions-export-envs:latest

.PHONY: setup-buildx
setup-buildx:
	docker buildx create --use --driver docker-container

.PHONY: build
build: setup-buildx
	docker buildx build . \
		--tag "${PKG_NAME}" \
		--platform "linux/amd64" \
		--output "type=docker" \
		--cache-from "type=gha,scope=${DOCKER_SCOPE}" \
		--cache-to "type=gha,mode=max,scope=${DOCKER_SCOPE}"

.PHONY: build
build: setup-buildx
docker buildx build . \
--tag "${DOCKER_IMAGE_FULL_NAME}" \
--platform "linux/amd64" \
--output "type=docker" \
--cache-from "type=gha,scope=${DOCKER_SCOPE}" \
--cache-to "type=gha,mode=max,scope=${DOCKER_SCOPE}"

name: CI

on:
  push:
  pull_request:

jobs:
  main:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v3

      - uses: peaceiris/actions-export-envs@v1.1.0
        id: envs

      - run: make build
        env:
          ACTIONS_RUNTIME_TOKEN: ${{ steps.envs.outputs.ACTIONS_RUNTIME_TOKEN }}
          ACTIONS_CACHE_URL: ${{ steps.envs.outputs.ACTIONS_CACHE_URL }}

- uses: ./
id: envs
- run: make build
env:
ACTIONS_RUNTIME_TOKEN: ${{ steps.envs.outputs.ACTIONS_RUNTIME_TOKEN }}
ACTIONS_CACHE_URL: ${{ steps.envs.outputs.ACTIONS_CACHE_URL }}

About

Exporting ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL to enable the Docker layer caching on GitHub Actions.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 4

  •  
  •  
  •  
  •