-
You should have github repo with
.envcreated insecrets.ENV_FILEand be registered in ghcr (docker registry from Github). -
Ensure, that your working machine is
self-hosted(https://github.com/user/project/settings/actions/runners). -
CR_PATvariable should be exported as github token on machine env. -
You can pull and start docker container without Github actions on host-runner machine.
Created
November 20, 2023 13:51
-
-
Save Pyroarsonist/d74af1cb8df5a81dfb0054e86abe7085 to your computer and use it in GitHub Desktop.
Build and deploy using ghcr
This file contains hidden or 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 | |
| on: | |
| push: | |
| branches: | |
| - master | |
| jobs: | |
| build: | |
| runs-on: self-hosted | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Create env file | |
| env: | |
| ENV_FILE: ${{ secrets.ENV_FILE }} | |
| run: echo "$ENV_FILE" > .env | |
| - name: Build docker container and push to ghcr | |
| run: bash ./docker-build.sh | |
| deploy: | |
| runs-on: self-hosted | |
| needs: build | |
| steps: | |
| - name: Remove old docker container | |
| run: docker ps -q --filter "name=your-project" | xargs -r docker stop && docker ps -aq --filter "name=your-project" | xargs -r docker rm | |
| - name: Deploy of docker container | |
| run: docker run --name your-project -p 3230:80 -d ghcr.io/your-user/your-project |
This file contains hidden or 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
| #!/bin/bash | |
| PACKAGE_VERSION=$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' package.json) | |
| echo "Building your-project with v$PACKAGE_VERSION" | |
| echo "$CR_PAT" | docker login ghcr.io -u your-user --password-stdin | |
| docker build -t "ghcr.io/your-user/your-project:$PACKAGE_VERSION" -t ghcr.io/your-user/your-project . | |
| docker push "ghcr.io/your-user/your-project:$PACKAGE_VERSION" | |
| docker push ghcr.io/your-user/your-project |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment