mirror of
https://github.com/zhaofengli/attic.git
synced 2025-03-15 21:08:23 +00:00
feat: Build & Push images as part of CI (#44)
This commit is contained in:
parent
171c89fbe0
commit
5f85e35a25
1 changed files with 33 additions and 0 deletions
33
.github/workflows/build.yml
vendored
33
.github/workflows/build.yml
vendored
|
@ -2,6 +2,9 @@ name: Build
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -10,6 +13,9 @@ jobs:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-11
|
- macos-11
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3.3.0
|
- uses: actions/checkout@v3.3.0
|
||||||
|
|
||||||
|
@ -50,3 +56,30 @@ jobs:
|
||||||
nix build .#internal."$system".attic-tests .#internal."$system".cargoArtifacts --no-link --print-out-paths -L | \
|
nix build .#internal."$system".attic-tests .#internal."$system".cargoArtifacts --no-link --print-out-paths -L | \
|
||||||
xargs attic push "ci:$ATTIC_CACHE"
|
xargs attic push "ci:$ATTIC_CACHE"
|
||||||
fi
|
fi
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
|
||||||
|
if: runner.os == 'Linux' && github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Push build container image
|
||||||
|
if: runner.os == 'Linux' && github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
||||||
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
IMAGE_ID=ghcr.io/${IMAGE_NAME}
|
||||||
|
TARBALL=$(nix build --json .#attic-server-image | jq -r '.[].outputs.out')
|
||||||
|
BRANCH=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
|
||||||
|
TAG="${{ github.sha }}"
|
||||||
|
[[ "${{ github.ref }}" == "refs/tags/"* ]] && TAG=$(echo $BRANCH | sed -e 's/^v//')
|
||||||
|
docker load < ${TARBALL}
|
||||||
|
echo IMAGE_ID=$IMAGE_ID
|
||||||
|
echo TAG=$TAG
|
||||||
|
docker tag attic-server:main "${IMAGE_ID}:${TAG}"
|
||||||
|
docker push ${IMAGE_ID}:${TAG}
|
||||||
|
if [ "$BRANCH" == "main" ]; then
|
||||||
|
TAG="latest"
|
||||||
|
docker tag attic-server:main "${IMAGE_ID}:${TAG}"
|
||||||
|
docker push ${IMAGE_ID}:${TAG}
|
||||||
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue