Skip to content

Commit

Permalink
Merge pull request #15 from azazak123/feat/migrate-to-gcp
Browse files Browse the repository at this point in the history
  • Loading branch information
azazak123 authored Mar 4, 2024
2 parents 2bcb763 + 9c7dc84 commit adb381f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 47 deletions.
51 changes: 38 additions & 13 deletions .github/workflows/deploy-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,49 @@ on:
push:
branches:
- "master"

env:
PROJECT_ID: pure-feat-410619
REGION: europe
IMAGE_LOCATION: europe-docker.pkg.dev/pure-feat-410619/avatar-bot
IMAGE: avatar-bot:latest
SERVICE: avatar-bot

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22

- name: Install Nix
uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: dprosper/[email protected]

- name: GCP auth
uses: google-github-actions/auth@v1
with:
API_KEY: ${{ secrets.API_KEY }}
INSTALL_PLUGINS: cloud-functions
REGION: eu-de
- name: Setup ibmcloud
run: ibmcloud fn namespace target Avatar-bot
- name: Build static
run: nix build .#static
- name: Create actions
run: nix develop --command dune build @create-actions
- name: Redeploy
run: nix develop --command dune build @redeploy
credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1

- name: Docker auth
run: |
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
- name: Build image
run: |
nix build .#staticDocker
docker load --input result
docker tag ${{ env.IMAGE }} ${{ env.IMAGE_LOCATION }}/${{ env.IMAGE }}
- name: Push image
run: docker push ${{ env.IMAGE_LOCATION }}/${{ env.IMAGE }}

- name: Deploy to cloud run
run: |
gcloud run deploy ${{ env.SERVICE }} --region europe-west1 \
--image ${{ env.IMAGE_LOCATION }}/${{ env.IMAGE }} \
--set-env-vars=HOST=0.0.0.0 --set-secrets=BOT_TOKEN=BOT_TOKEN_PROD:latest \
--memory 128Mi --cpu 1 --max-instances 5
23 changes: 0 additions & 23 deletions dune
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
(rule
(alias create-actions)
(deps (universe))
(action
(progn
(system "mkdir -p ../../actions")
(system "cd ../../actions && cp -f ../result/bin/avatar-bot exec")
(system "cd ../../actions && zip avatar-bot exec"))))

(rule
(alias deploy)
(deps (universe))
(action
(system
"cd ../.. && ibmcloud fn action create avatar-bot --native actions/avatar-bot.zip --param bot_token $BOT_TOKEN --web true")))

(rule
(alias redeploy)
(deps (universe))
(action
(system
"cd ../.. && ibmcloud fn action update avatar-bot --native actions/avatar-bot.zip")))

(env
(static
(flags
Expand Down
16 changes: 5 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,13 @@

getDevPackages = pkgs:
with pkgs;[
zip

# Nix tools
nil
nixpkgs-fmt
];

getIbmcloud = pkgs: with pkgs;[
# Faas provider
ibmcloud-cli
];
# Cloud provider
google-cloud-sdk
];

overlay = final: prev: {
${package} = prev.${package}.overrideAttrs
Expand Down Expand Up @@ -112,8 +108,7 @@
inputsFrom = [ packages.${system}.default ];
buildInputs =
getOcamlDevPackages pkgs scope
++ getDevPackages pkgs
++ getIbmcloud nixpkgs-unstable.legacyPackages.${system};
++ getDevPackages pkgs;

shellHook = ''
set -a
Expand Down Expand Up @@ -159,8 +154,7 @@
devShells.x86_64-linux.static = pkgsMusl.mkShell {
inputsFrom = [ mainMusl ];
buildInputs = getOcamlDevPackages pkgs scopeMusl
++ getDevPackages pkgs
++ getIbmcloud nixpkgs-unstable.legacyPackages.x86_64-linux;
++ getDevPackages pkgs;

shellHook = ''
set -a
Expand Down

0 comments on commit adb381f

Please sign in to comment.