Skip to content

Commit

Permalink
fix: upload artifact github action
Browse files Browse the repository at this point in the history
  • Loading branch information
thuan2172001 committed Feb 25, 2024
1 parent 6f96435 commit 6df26c3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
35 changes: 20 additions & 15 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,62 +59,67 @@ jobs:
release-github-artifact:
name: Release Packaging
env:
PROJECT_NAME_UNDERSCORE: rust-api-server
PROJECT_NAME_UNDERSCORE: rust-server
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [cargo-check, fmt-check, test-and-coverage]
steps:
- name: Check out from Git
uses: actions/checkout@v4

- name: Grant permission to run command
run: echo 'ACTIONS_ALLOW_UNSECURE_COMMANDS=true' >> $GITHUB_ENV

- name: Check if Git tag exists
run: echo "::set-env name=HEAD_TAG::$(git tag --points-at HEAD)"

- name: Skip if Git tag does not exist
if: steps.check-tag.outputs.HEAD_TAG == ''
run: exit 0 # Exit with success, effectively skipping subsequent steps

- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Release Build
run: cargo build --release
run: cargo build --release --bin cli

- name: "Upload Artifact"
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECT_NAME_UNDERSCORE }}
path: target/release/${{ env.PROJECT_NAME_UNDERSCORE }}
path: target/release/cli

release-docker-image:
env:
DOCKER_HUB_REPOSITORY: thuan2172001/rust-server
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [cargo-check, fmt-check, test-and-coverage]
steps:
- name: Check out from Git
uses: actions/checkout@v4

- name: Grant permission to run command
run: echo 'ACTIONS_ALLOW_UNSECURE_COMMANDS=true' >> $GITHUB_ENV

- name: Check if Git tag exists
run: echo "::set-env name=HEAD_TAG::$(git tag --points-at HEAD)"

- name: Skip if Git tag does not exist
if: steps.check-tag.outputs.HEAD_TAG == ''
run: exit 0 # Exit with success, effectively skipping subsequent steps

- name: Checkout
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
target: prod
load: true

- name: Build and push docker image
run: |
docker build . --tag ${{ env.DOCKER_HUB_REPOSITORY }}:latest
docker push ${{ env.DOCKER_HUB_REPOSITORY }}:latest
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@
Welcome to the Rust API Server! This server provides a simple REST interface for your applications. This README will
guide you through setting up and running the server, as well as configuring its various options.

## Deploy
**Automated Builds:**
Builds are automatically generated for each commit to the repository in the `main` branch and are subsequently pushed to Docker Hub. Tags are applied using the commit SHA, branch name, and the latest tag if released on the main branch. You can find a list of available tags [here](https://hub.docker.com/r/thuan2172001/rust-server/tags).

**Release Binaries:**
For every release, separate `cli` binaries are built. These binaries can be downloaded from [here](https://github.com/sonntuet1997/rust-web-api-microservice-template/releases) and are available for various operating systems and architectures. You are welcome to use the automated binaries or build your own.

**Contributions and PRs:**
If you submit a pull request, please note that images are not built by default. A maintainer will need to retag them for the build process to take place.

### Docker
1. Pull the docker image
```commit to only the main branch
docker pull thuan2172001/rust-server:latest
```

2. Run the image
```
docker run -d -p 8000:8000 thuan2172001/rust-server:latest
```

## How To Run

To get started, execute the following command in your terminal:
Expand Down

0 comments on commit 6df26c3

Please sign in to comment.