-
Notifications
You must be signed in to change notification settings - Fork 0
Feature continuous deployment #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6d9b86a
feat: Remove unused code
magley 760d855
feat: Create docker scripts for integration tests
magley 237ea30
feat: Cache dependencies when running tests
magley 78ca6eb
refactor: Organize tests into subdirectories
magley 74a60e5
feat: Enforce LF endings for shell files
magley 9991825
feat: Add a test runner service
magley 50c979b
test: Add user register integration-test
magley 9110e54
feat: Add health check to user service
magley 732b160
feat: Use health checks when deploying
magley 6913839
test: Add more integration tests
magley 8fc31bf
refactor: Extract test utilities to `util.go`
magley 4cc7068
feat: Add integration tests to workflow
magley c2a1258
fix: Move to `src/` before making `test-out/`
magley 4ad9022
fix: Printf instead of echo for keys in workflow
magley 01ff048
feat: Add deployment step in workflow
magley e5f5a72
feat: Split test and deploy into two workflows
magley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| *.sh text eol=lf |
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: Deploy code | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - develop | ||
| - master | ||
|
|
||
| jobs: | ||
| build-and-deploy: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Generate Semantic Version | ||
| id: version | ||
| uses: PaulHatch/semantic-version@v4 | ||
| with: | ||
| tag_prefix: "v" | ||
| major_pattern: "feat!" | ||
| minor_pattern: "feat" | ||
| format: "${major}.${minor}.${patch}" | ||
|
|
||
| - name: Log version | ||
| run: echo "Version is ${{ steps.version.outputs.version }}" | ||
|
|
||
| - name: Set VERSION environment variable | ||
| run: echo "VERSION=${{ steps.version.outputs.version }}" >> $GITHUB_ENV | ||
|
|
||
| - name: Log in to DockerHub | ||
| uses: docker/login-action@v2 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
|
||
| - name: Build Docker image | ||
| run: docker compose build | ||
|
|
||
| - name: Push Docker image | ||
| run: docker compose push |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| name: Test on develop | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - develop | ||
|
|
||
| paths: | ||
| - 'src/**' | ||
| - 'compose.yml' | ||
| - '*.sh' | ||
|
|
||
| jobs: | ||
| unit-test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: 1.24 | ||
|
|
||
| - name: Cache Go modules | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/go/pkg/mod | ||
| ~/.cache/go-build | ||
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-go- | ||
|
|
||
| - name: Write private key from secret | ||
| run: printf "%s" "${{ secrets.PRIVATE_KEY }}" > keys/private_key.key | ||
|
|
||
| - name: Write public key from secret | ||
| run: printf "%s" "${{ secrets.PUBLIC_KEY }}" > keys/public_key.pem | ||
|
|
||
| - name: Set key permissions | ||
| run: chmod 400 keys/private_key.key | ||
|
|
||
| - name: Run test script | ||
| run: | | ||
| chmod +x ./run-tests.sh | ||
| ./run-tests.sh | ||
|
|
||
| - name: Upload test results as artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: unit-test-results | ||
| path: | | ||
| src/test-out/ | ||
|
|
||
| integration-test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: 1.24 | ||
|
|
||
| - name: Cache Go modules | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/go/pkg/mod | ||
| ~/.cache/go-build | ||
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-go- | ||
|
|
||
| - name: Write private key from secret | ||
| run: printf "%s" "${{ secrets.PRIVATE_KEY }}" > keys/private_key.key | ||
|
|
||
| - name: Write public key from secret | ||
| run: printf "%s" "${{ secrets.PUBLIC_KEY }}" > keys/public_key.pem | ||
|
|
||
| - name: Set key permissions | ||
| run: chmod 400 keys/private_key.key | ||
|
|
||
| - name: Run tests | ||
| run: docker compose -f compose.integration.yml up --build --abort-on-container-exit --exit-code-from test-runner | ||
|
|
||
| - name: Cleanup | ||
| run: docker compose -f compose.integration.yml down |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| services: | ||
| test-runner: | ||
| build: | ||
| context: ./src | ||
| dockerfile: test.Dockerfile | ||
| depends_on: | ||
| db: | ||
| condition: service_healthy | ||
| user-service: | ||
| condition: service_healthy | ||
| volumes: | ||
| - go-mod-cache:/go/pkg/mod | ||
|
|
||
| user-service: | ||
| build: | ||
| context: ./src | ||
| dockerfile: Dockerfile | ||
| image: user-service-test | ||
| ports: | ||
| - "0:8080" | ||
| environment: | ||
| DB_HOST: db | ||
| DB_PORT: 5432 | ||
| DB_NAME: bookem_userdb_test | ||
| DB_USER: bookem_userdb_user | ||
| DB_PASSWORD: testpass | ||
| JWT_PRIVATE_KEY_PATH: /app/keys/private_key.key | ||
| JWT_PUBLIC_KEY_PATH: /app/keys/public_key.pem | ||
| ENABLE_TEST_MODE: "true" | ||
| depends_on: | ||
| db: | ||
| condition: service_healthy | ||
| volumes: | ||
| - ./keys/private_key.key:/app/keys/private_key.key:ro | ||
| - ./keys/public_key.pem:/app/keys/public_key.pem:ro | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "wget --spider --tries=1 --no-verbose http://user-service:8080/healthz || exit 1"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| db: | ||
| image: postgres:15-alpine | ||
| environment: | ||
| POSTGRES_DB: bookem_userdb_test | ||
| POSTGRES_USER: bookem_userdb_user | ||
| POSTGRES_PASSWORD: testpass | ||
| ports: | ||
| - "0:5432" | ||
| volumes: | ||
| - type: tmpfs | ||
| target: /var/lib/postgresql/data | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| volumes: | ||
| go-mod-cache: |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,19 @@ | ||
| #!/bin/bash | ||
|
|
||
| cd src | ||
| mkdir test-out | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| echo "Running tests..." | ||
| echo "Running unit tests..." | ||
|
|
||
| cd src | ||
| go test -coverprofile=coverage.out -coverpkg=./... ./... | ||
| go tool cover -func=coverage.out | ||
| go test -v -coverprofile=./test-out/coverage-unit.out -coverpkg=./... ./test/unit/... | ||
|
|
||
| echo "Linting..." | ||
| echo "Building coverage report..." | ||
|
|
||
| go tool cover -func=./test-out/coverage-unit.out | ||
| go tool cover -html=./test-out/coverage-unit.out -o ./test-out/coverage-unit.html | ||
|
|
||
| go vet ./... | ||
| echo "Linting..." | ||
|
|
||
| echo "All checks passed!" | ||
| go vet ./... |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.