Build and Upload Image #41
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: Build and Deploy | |
run-name: Build and Upload Image | |
on: [push] | |
jobs: | |
container-build: | |
runs-on: christianbingman-com-runners | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Nix Deps | |
run: sudo apt install xz-utils | |
- uses: cachix/install-nix-action@v27 | |
with: | |
nix_path: nixpkgs=channel:nixos-unstable | |
- name: Build container | |
run: nix build .#docker | |
- name: Upload container | |
uses: actions/upload-artifact@v4 | |
with: | |
name: container.tar | |
path: ./result | |
container-push: | |
runs-on: christianbingman-com-runners | |
needs: container-build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
package.json | |
- name: Download container tar | |
uses: actions/download-artifact@v4 | |
with: | |
name: container.tar | |
- name: Load container image | |
run: docker load < result | |
- name: Tag image | |
run: | | |
COMMIT_TAG=$(jq -r .version package.json)-$GITHUB_SHA | |
echo "COMMIT_TAG=$COMMIT_TAG" >> "$GITHUB_ENV" | |
docker tag registry.christianbingman.com/personal-site:latest registry.christianbingman.com/personal-site:$COMMIT_TAG | |
if [[ "$GITHUB_REF_TYPE" == "tag" ]]; then | |
docker tag registry.christianbingman.com/personal-site:latest registry.christianbingman.com/personal-site:$(jq -r .version package.json) | |
fi | |
- name: Push image to repo | |
run: "docker push registry.christianbingman.com/personal-site:$COMMIT_TAG" | |
- name: Push production image | |
if: github.ref_type == 'tag' | |
run: "docker push registry.christianbingman.com/personal-site:$(jq -r .version package.json)" | |
update-chart: | |
runs-on: christianbingman-com-runners | |
needs: container-build | |
steps: | |
- name: Checkout package.json | |
uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
package.json | |
- name: Checkout helm repo | |
uses: actions/checkout@v4 | |
with: | |
repository: ChristianBingman/christianbingman-com-helm | |
token: ${{ secrets.HELM_PAT }} | |
ref: main | |
path: chart | |
- name: Setup env | |
run: echo "COMMIT_TAG=$(jq -r .version package.json)-$GITHUB_SHA" >> "$GITHUB_ENV" | |
- name: Update int environment | |
run: | | |
cd chart | |
sed -i -e "s/tag: .*$/tag: $COMMIT_TAG/g" int.yaml | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "[email protected]" | |
git add int.yaml | |
git commit -m "Deploy [int]" | |
git push |