Make repo optional and default to github name #199
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Self-test: Multistage docker build" | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
# Help Dependabot checks run | |
permissions: | |
checks: write | |
contents: read | |
packages: write | |
jobs: | |
test-build-auto-repo: | |
name: Test automatic repository naming | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Auth to GH registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: ./ | |
id: build | |
with: | |
dockerfile: examples/Dockerfile | |
registry: ghcr.io | |
stages: env, configured | |
server-stage: server | |
- name: Print outputs | |
run: | | |
echo "Server: ${{ steps.build.outputs.server-tag }}" | |
echo "Testenv: ${{ steps.build.outputs.testenv-tag }}" | |
echo "Commit: ${{ steps.build.outputs.commit }}" | |
- name: Run image | |
run: docker run --rm ${{ steps.build.outputs.server-tag }} | |
test-build-parallel-setting: | |
name: Parallel via setting | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
parallel: [true, false] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Auth to GH registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: generate file change | |
run: echo $GITHUB_SHA > file.txt | |
- uses: ./ | |
id: build | |
with: | |
build-args: BUILD_ARG_1=hello | |
dockerfile: examples/Dockerfile | |
repository: ghcr.io/firehed/actions | |
parallel: ${{ matrix.parallel }} | |
server-stage: server | |
quiet: false | |
test-build-parallel-buildkit: | |
name: Parallel via DOCKER_BUILDKIT | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_BUILDKIT: "1" | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Auth to GH registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: generate file change | |
run: echo $GITHUB_SHA > file.txt | |
- uses: ./ | |
id: build | |
with: | |
build-args: BUILD_ARG_1=hello | |
dockerfile: examples/Dockerfile | |
repository: ghcr.io/firehed/actions | |
server-stage: server | |
quiet: false | |
build: | |
name: Build docker images | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
buildkit: ["0", "1"] | |
env: | |
DOCKER_BUILDKIT: ${{ matrix.buildkit }} | |
outputs: | |
testenv-tag: ${{ steps.build.outputs.testenv-tag }} | |
server-tag: ${{ steps.build.outputs.server-tag }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Auth to GH registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: generate file change | |
run: echo $GITHUB_SHA > file.txt | |
- uses: ./ | |
id: build | |
with: | |
build-args: BUILD_ARG_1=hello, BUILD_ARG_2=goodbye, version=${{ github.sha }} | |
dockerfile: examples/Dockerfile | |
# repository: firehed/actions | |
# repository: gcr.io/firehed/actions | |
repository: ghcr.io/firehed/actions | |
stages: env, configured | |
testenv-stage: testenv | |
server-stage: server | |
quiet: false | |
test: | |
name: 'test' | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
steps: | |
- name: run tests | |
run: | |
docker run | |
--rm | |
${{ needs.build.outputs.testenv-tag }} | |
echo "I'm a test!" | |
- name: get build arg1 | |
id: build-args | |
run: docker run | |
--rm | |
${{ needs.build.outputs.testenv-tag }} | |
sh examples/print-outputs.sh | |
- name: validate build arg 1 | |
if: ${{ steps.build-args.outputs.arg1 != 'hello' }} | |
run: exit 1 | |
- name: validate build arg 2 | |
if: ${{ steps.build-args.outputs.arg2 != 'goodbye' }} | |
run: exit 1 | |
- name: display server | |
run: echo ${{ needs.build.outputs.server-tag }} | |
build-server-only: | |
name: Build server image only | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Auth to GH registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: ./ | |
id: build | |
with: | |
dockerfile: examples/Dockerfile | |
repository: ghcr.io/firehed/actions | |
stages: env, configured | |
server-stage: server | |
- name: Print outputs | |
run: | | |
echo "Server: ${{ steps.build.outputs.server-tag }}" | |
echo "Testenv: ${{ steps.build.outputs.testenv-tag }}" | |
echo "Commit: ${{ steps.build.outputs.commit }}" | |
- name: Run image | |
run: docker run --rm ${{ steps.build.outputs.server-tag }} | |
build-different-context: | |
name: Override context | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Auth to GH registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: ./ | |
name: Build with this action | |
id: build | |
with: | |
context: examples | |
repository: ghcr.io/firehed/actions | |
stages: env, configured | |
server-stage: server | |
- name: Print outputs | |
run: | | |
echo "Server: ${{ steps.build.outputs.server-tag }}" | |
echo "Testenv: ${{ steps.build.outputs.testenv-tag }}" | |
echo "Commit: ${{ steps.build.outputs.commit }}" | |
- name: Run image | |
run: docker run --rm ${{ steps.build.outputs.server-tag }} | |
build-different-context-and-dockerfile: | |
name: Override context and file | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Auth to GH registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: ./ | |
name: Build with this action | |
id: build | |
with: | |
context: examples | |
dockerfile: examples/Dockerfile | |
repository: ghcr.io/firehed/actions | |
stages: env, configured | |
server-stage: server | |
- name: Print outputs | |
run: | | |
echo "Server: ${{ steps.build.outputs.server-tag }}" | |
echo "Testenv: ${{ steps.build.outputs.testenv-tag }}" | |
echo "Commit: ${{ steps.build.outputs.commit }}" | |
- name: Run image | |
run: docker run --rm ${{ steps.build.outputs.server-tag }} | |
expect-error-build-failure: | |
name: Action should fail if docker build fails | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Auth to GH registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: ./ | |
name: Build with bad settings | |
continue-on-error: true | |
id: build | |
with: | |
# No context/dockerfile | |
server-stage: server | |
repository: ghcr.io/firehed/actions | |
- name: expect failure | |
if: steps.build.outcome == 'success' | |
run: exit 1 | |
expect-error-push-failure: | |
name: Action should fail if docker push fails | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
# Do not log in to docker registry. This will cause the push to fail | |
- uses: ./ | |
name: Build without login | |
continue-on-error: true | |
id: build | |
with: | |
context: examples | |
repository: ghcr.io/firehed/actions | |
stages: env, configured | |
server-stage: server | |
- name: expect failure | |
if: steps.build.outcome == 'success' | |
run: exit 1 |