|
| 1 | +name: Docker Image CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + tags: [ '*.*.*' ] |
| 7 | + pull_request: |
| 8 | + branches: [ master ] |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + versionTag: |
| 12 | + description: 'Version tag to push to Docker Hub (lowercase, alphanumeric)' |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +jobs: |
| 17 | + |
| 18 | + build_test_push: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + strategy: |
| 21 | + fail-fast: false # So that remaining jobs don't instantly quit if one fails (e.g, CPU/ROCm don't upload if CUDA just fails to push to ghcr...) |
| 22 | + # matrix: |
| 23 | + # include: # Platform locates Dockerfile ("Dockerfile-{PLATFORM}"), docker tag has to be all lowercase alphanumeric for mysterious docker reasons |
| 24 | + # - platform: CPU |
| 25 | + # dockertag: cpu |
| 26 | + # - platform: ROCm |
| 27 | + # dockertag: rocm |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Check out the repository |
| 31 | + uses: actions/checkout@v3 |
| 32 | + # with: |
| 33 | + # lfs: false |
| 34 | + # submodules: 'recursive' |
| 35 | + |
| 36 | + # - name: Check if the repository has changed |
| 37 | + # run: ls -l |
| 38 | + |
| 39 | + - name: Docker prune to save space # If you switch to self-hosted runners, this should be removed. |
| 40 | + run: echo y | docker system prune -a |
| 41 | + |
| 42 | + - name: Check free space before |
| 43 | + run: | |
| 44 | + echo "Free space:" |
| 45 | + df -h |
| 46 | + |
| 47 | + - name: Free Disk Space (Ubuntu) |
| 48 | + run: | |
| 49 | + sudo rm -rf /usr/local/lib/android |
| 50 | + sudo rm -rf /usr/share/dotnet |
| 51 | + |
| 52 | + - name: Check free space after |
| 53 | + run: | |
| 54 | + echo "Free space:" |
| 55 | + df -h |
| 56 | + |
| 57 | + # Install the cosign tool except on PR |
| 58 | + # https://github.com/sigstore/cosign-installer |
| 59 | + - name: Install cosign |
| 60 | + if: github.event_name != 'pull_request' |
| 61 | + uses: sigstore/cosign-installer@1e95c1de343b5b0c23352d6417ee3e48d5bcd422 |
| 62 | + with: |
| 63 | + cosign-release: 'v1.4.0' |
| 64 | + |
| 65 | + - name: Log into GitHub Packages registry (ghcr.io) |
| 66 | + if: github.event_name != 'pull_request' |
| 67 | + uses: docker/#-action@v2 |
| 68 | + with: |
| 69 | + registry: ghcr.io |
| 70 | + username: ${{ github.actor }} |
| 71 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + |
| 73 | + # Extract metadata (tags, labels) for Docker |
| 74 | + # https://github.com/docker/metadata-action |
| 75 | + - name: Extract Docker metadata |
| 76 | + id: meta |
| 77 | + uses: docker/metadata-action@v4 |
| 78 | + with: |
| 79 | + images: ghcr.io/fets-ai/front-end |
| 80 | + flavor: | # Handle prefixing and "latest" generation -- use "tags" property to specify events/tags further |
| 81 | + latest=true |
| 82 | + tags: | |
| 83 | + type=semver,pattern={{version}} |
| 84 | + type=ref,event=branch |
| 85 | + type=ref,event=pr |
| 86 | + type=ref,event=tag |
| 87 | +
|
| 88 | + # Build Docker Image (but don't push yet -- wait for the test step first). |
| 89 | + # https://github.com/docker/build-push-action |
| 90 | + - name: Build Docker images |
| 91 | + id: build |
| 92 | + uses: docker/build-push-action@v4 |
| 93 | + with: |
| 94 | + context: . |
| 95 | + # cache-from: type=local,src=${{ github.workspace }} |
| 96 | + # build-args: --mount 'type=bind,src=${{ github.workspace }},target=/Front-End,readwrite' #-v ${{ github.workspace }}:/Front-End |
| 97 | + file: ./Dockerfile |
| 98 | + push: false |
| 99 | + load: true |
| 100 | + tags: ${{ steps.meta.outputs.tags }} |
| 101 | + labels: ${{ steps.meta.outputs.labels }} |
| 102 | + |
| 103 | + # - uses: addnab/docker-run-action@v3 |
| 104 | + # with: |
| 105 | + # username: ${{ github.actor }} |
| 106 | + # password: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + # registry: ghcr.io |
| 108 | + # image: ghcr.io/fets-ai/front-end:latest |
| 109 | + # options: -v ${{ github.workspace }}:/Front-End |
| 110 | + # run: | |
| 111 | + # echo "Running Script" |
| 112 | + # /work/run-script |
| 113 | + # - name: Build the Docker image |
| 114 | + # run: docker build . -v /Front-End:/home/runner/work/Front-End/Front-End/ --file Dockerfile --tag ${{ steps.meta.outputs.tags }} |
| 115 | + |
| 116 | + |
| 117 | + # Run the image from the base entrypoint as a test |
| 118 | + - name: Test container with entrypoint |
| 119 | + # Run a tag we generated from the metadata extraction above -- they're all the same image, but echo it regardless just so we know. |
| 120 | + run: docker run --rm ghcr.io/fets-ai/front-end:latest -h |
| 121 | + |
| 122 | + # Push Docker image with Buildx (but don't push on PR) |
| 123 | + # https://github.com/docker/build-push-action |
| 124 | + # This won't re-build the images fully or anything, they should already exist from the build step and use the cache. |
| 125 | + - name: Upload to Docker Hub (docker.io) and GitHub Packages (ghcr.io) |
| 126 | + id: upload |
| 127 | + if: github.event_name != 'pull_request' |
| 128 | + uses: docker/build-push-action@v4 |
| 129 | + with: |
| 130 | + context: . |
| 131 | + file: ./Dockerfile |
| 132 | + push: true |
| 133 | + tags: ${{ steps.meta.outputs.tags }} |
| 134 | + labels: ${{ steps.meta.outputs.labels }} |
| 135 | + |
| 136 | + # Below is for signing images (keyless) with cosign. But this adds confusing sha256-digest.sig tags to the container registry. |
| 137 | + # Leave this commented if container signing is not required. |
| 138 | + # # Sign the resulting Docker image digest except on PRs. |
| 139 | + # # Uses cosign keyless signing: https://github.com/sigstore/cosign/blob/main/KEYLESS.md |
| 140 | + # # This will only write to the public Rekor transparency log when the Docker |
| 141 | + # # repository is public to avoid leaking data. If you would like to publish |
| 142 | + # # transparency data even for private images, pass --force to cosign below. |
| 143 | + # # https://github.com/sigstore/cosign |
| 144 | + #- name: Sign published Docker image (ghcr.io) |
| 145 | + # if: ${{ github.event_name != 'pull_request' }} |
| 146 | + # env: |
| 147 | + # COSIGN_EXPERIMENTAL: "true" |
| 148 | + # # This step uses the identity token to provision an ephemeral certificate |
| 149 | + # # against the sigstore community Fulcio instance. |
| 150 | + # run: cosign sign ghcr.io/fets-ai/front-end@${{ steps.upload.outputs.digest }} |
| 151 | + |
0 commit comments